Woocommerce创建自定义变量产品类型

时间:2016-07-12 06:54:52

标签: php wordpress woocommerce

我正在尝试从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
        }
    }
}

2 个答案:

答案 0 :(得分:2)

我已经成功地通过在变体和属性标签中添加回来。下一步是在“添加为变体”选项中添加。

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);  

答案 1 :(得分:1)

丹·李约瑟的回答是你应该遵循的第一步,之后你应该使用这个

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所说的缺少的复选框选项。