相关疑难解决方法(0)

在WooCommerce变量产品单页中获取所选的产品变体ID

对于我的Woocommerce变量产品,我在单个产品页面上实现了自定义大小的选择器,并在表格中具有以下尺寸:

在此输入图像描述

这些变化只是:30B 30C 30D而不是被分成:30B C D

我想弄清楚的是:如何抓住每个产品变化的运输类?

我在购物车页面上有类似的内容,但我不知道变体ID是什么或如何从单个产品页面获取它:

$product_id = ( 0 != $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
// need the variation id for the above to be able to do the rest:

$product_shipping_classes = get_the_terms( $product_id, 'product_shipping_class' );
$product_shipping_class_name = ( $product_shipping_classes && ! is_wp_error( $product_shipping_classes ) ) ? current( $product_shipping_classes )->name : '';
Run Code Online (Sandbox Code Playgroud)

我知道如果有变体ID,该怎么做.我只是无法弄清楚如何得到它以便做其余的事情.我需要得到的唯一东西是产品ID和变体的slug(这个页面上还有一个颜色属性).

但是我已经为产品提供了一个默认的变体(所以variation_id设置了隐藏).

也许需要首先获取所选颜色的ID然后获取其他颜色的变化ID?

php wordpress jquery variations woocommerce

2
推荐指数
1
解决办法
5981
查看次数

替换价格范围处理Woocommerce 3中的默认变化显示价格

在我们的woocommerce网站上,我试图根据客户从下拉菜单中选择的变化来更新显示的价格,如下所示:

下拉变化选择示例

我使用了LoictheAztec在另一个答案中提交的php函数:
用WooCommerce 3中的选定变动价格替换可变价格范围

add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
function move_variations_single_price(){
    global $product, $post;

    if ( $product->is_type( 'variable' ) ) {
        // removing the variations price for variable products
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

        // Change location and inserting back the variations price
        add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
    }
}

function replace_variation_single_price(){
    global $product;

    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' …
Run Code Online (Sandbox Code Playgroud)

php wordpress variations woocommerce price

1
推荐指数
1
解决办法
2607
查看次数

标签 统计

php ×2

variations ×2

woocommerce ×2

wordpress ×2

jquery ×1

price ×1