Last active
May 15, 2026 04:34
-
-
Save rajeshsingh520/cb17b41a559ed6b23e78e2cb4d07e167 to your computer and use it in GitHub Desktop.
option to hide enq button for product on the loop pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PIE_Disable_Archive_Enquiry { | |
| private static $instance = null; | |
| public $loop_product_enquiry_position; | |
| public $add_to_enquiry_text_loop_variable; | |
| public static function instance() { | |
| return self::$instance ?: self::$instance = new self(); | |
| } | |
| private function __construct() { | |
| $this->loop_product_enquiry_position = get_option('pi_eqw_enquiry_loop_position','woocommerce_after_shop_loop_item'); | |
| $this->add_to_enquiry_text_loop_variable = get_option('pi_eqw_enquiry_loop_button_text_variable','Add to Enquiry'); | |
| add_action( 'add_meta_boxes', [ $this, 'add_metabox' ] ); | |
| add_action( 'save_post_product', [ $this, 'save' ] ); | |
| add_filter('pisol_eqw_show_enq_on_loop_page',[$this, 'disable'], 10, 2); | |
| add_action($this->loop_product_enquiry_position, array($this,'add_loop_enquiry_button'), 50 ); | |
| } | |
| function add_loop_enquiry_button() { | |
| global $product; | |
| $product_id = $product->get_id(); | |
| $disable = get_post_meta( $product_id, '_pie_disable_archive_enquiry', true ); | |
| if(empty($disable)) return; | |
| echo '<div style="margin-bottom:10px; text-align:center; width:100%;">'; | |
| $button_txt = $this->add_to_enquiry_text_loop_variable; | |
| echo '<a class="button pi-custom-button add-to-enquiry-loop pi-enq-product-'.esc_attr($product->get_id()).'" href="'.$product->get_permalink().'">'.esc_html($button_txt).'</a>'; | |
| echo '</div>'; | |
| } | |
| function disable($enable, $product){ | |
| $product_id = $product->get_id(); | |
| $disable = get_post_meta( $product_id, '_pie_disable_archive_enquiry', true ); | |
| if(!empty($disable)) return false; | |
| return $enable; | |
| } | |
| public function add_metabox() { | |
| add_meta_box( | |
| 'pie_disable_archive_enquiry', | |
| __( 'Enquiry Settings', 'textdomain' ), | |
| [ $this, 'metabox_html' ], | |
| 'product', | |
| 'side' | |
| ); | |
| } | |
| public function metabox_html( $post ) { | |
| if ( 'simple' !== get_post_type_object( $post->post_type ) ? '' : wc_get_product( $post->ID )->get_type() ) { | |
| echo '<p>' . esc_html__( 'Only for simple products.', 'textdomain' ) . '</p>'; | |
| return; | |
| } | |
| wp_nonce_field( 'pie_save_archive_enquiry', 'pie_archive_enquiry_nonce' ); | |
| $value = get_post_meta( $post->ID, '_pie_disable_archive_enquiry', true ); | |
| ?> | |
| <label> | |
| <input type="checkbox" name="_pie_disable_archive_enquiry" value="1" <?php checked( $value, '1' ); ?> /> | |
| <?php esc_html_e( 'Disable Add to Enquiry on Archive Page', 'textdomain' ); ?> | |
| </label> | |
| <?php | |
| } | |
| public function save( $post_id ) { | |
| if ( | |
| ! isset( $_POST['pie_archive_enquiry_nonce'] ) || | |
| ! wp_verify_nonce( $_POST['pie_archive_enquiry_nonce'], 'pie_save_archive_enquiry' ) | |
| ) { | |
| return; | |
| } | |
| update_post_meta( | |
| $post_id, | |
| '_pie_disable_archive_enquiry', | |
| isset( $_POST['_pie_disable_archive_enquiry'] ) ? '1' : '' | |
| ); | |
| } | |
| } | |
| PIE_Disable_Archive_Enquiry::instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment