View Categories

WooCommerce:单个页面POA/询价

< 1 min read

当您有一个价格为空的产品时,您可能想显示“ POA”价格和/或“ Call for Price”按钮。
仿牌独立站出海专家

PHP代码段:如果价格为空,则显示“ POA”和询价按钮


add_filter( 'woocommerce_empty_price_html', 'bbloomer_poa_and_enquiry_cf7_woocommerce' );
  
function bbloomer_poa_and_enquiry_cf7_woocommerce() {
   echo '<div class="poa">POA</div><button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Product Inquiry</button>';
   echo '<div id="product_inq" style="display:none">';
   echo do_shortcode('[paste_your_contact_form_7_shortcode_here]');
   echo '</div>';
   wc_enqueue_js( "
      $('#trigger_cf').on('click', function(){
         if ( $(this).text() == 'Product Inquiry' ) {
            $('#product_inq').css('display','block');
            $('input[name="your-subject"]').val('<?php the_title(); ?>');
            $('#trigger_cf').html('Close');
         } else {
            $('#product_inq').hide();
            $('#trigger_cf').html('Product Inquiry');
         }
      });
   " );
}