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

标签 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
        }
    }
}

最佳答案

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

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

关于php - Woocommerce 创建自定义变量产品类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38321915/

相关文章:

php - 如何在 CodeIgniter 3 中的默认 Controller 路由中使用子文件夹

php - 如何在 Laravel 中打印与其类别名称相关的品牌名称?

php - laravel 5.7 数据未传递到 View

PHP Compact() 函数返回一个空数组

wordpress - 如何处理 Docker 镜像中的安全更新?

php - 从 localhost wordpress 更改为 live site wordpress

wordpress - 如何在Contact Form 7 WordPress中实现Google Adwords转换代码

php - 更改特定 woocommerce 类别存档的默认排序顺序

php - 需要有关 REST API(网络服务)的帮助以进行 woocommerce 结帐

mysql - 组合来自 MYSQL 的选择值,然后细化落在某个范围内的值