【问题标题】:Woocommerce Creating a custom variable product typeWoocommerce 创建自定义变量产品类型
【发布时间】:2016-11-14 06:49:34
【问题描述】:

我正在尝试从 woocommerce 为预订表单创建自定义变量产品类型,该表单根据一组变量具有不同的定价。

我已成功添加自定义产品类型。但是我如何为不同的属性定价复制可变产品具有的相同选项。似乎找不到与可变产品类型相关的任何资源。

// add a product type
add_filter( 'product_type_selector', 'cpt_add_custom_product_type' );
function cpt_add_custom_product_type( $types ){
    $types[ 'booking_product' ] = __( 'Booking Product' );
    return $types;
}
add_action( 'plugins_loaded', 'cpt_create_custom_product_type' );
function cpt_create_custom_product_type(){
     // declare the product class
     class WC_Product_Wdm extends WC_Product_Variable {
        public function __construct( $product ) {
           $this->product_type = 'booking_product';
           parent::__construct( $product );
           // add additional functions here
        }
    }
}

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我已经设法部分解决了 - 通过重新添加变体和属性选项卡。下一步是在“添加为变体”选项中重新添加。

    add_filter('woocommerce_product_data_tabs', function($tabs) {
    
                array_push($tabs['attribute']['class'], 'show_if_variable show_if_membership');
                array_push($tabs['variations']['class'], 'show_if_membership');
    
                return $tabs;
    
            }, 10, 1);  
    

    【讨论】:

      【解决方案2】:

      Dan Needham 的回答是您应该遵循的第一步,然后您应该使用它

      function producttype_custom_js() {
      
      if ( 'product' != get_post_type() ) :
          return;
      endif;
      
      ?><script type='text/javascript'>
          jQuery( document ).ready( function() {
              jQuery( '.enable_variation' ).addClass( 'show_if_cus_producttype' ).show();
          });
      
      </script><?php 
      } 
      
      add_action( 'admin_footer', 'producttype_custom_js' );
      

      这将添加 Dan Needham 所说的复选框选项缺失。

      【讨论】:

      • 自定义产品类型如何设置模板?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2016-09-28
      • 2016-09-04
      • 2022-01-02
      • 2021-07-24
      • 2016-02-12
      • 1970-01-01
      相关资源
      最近更新 更多