在WooCommerce中,使用以下代码在简单和变量产品中的产品价格之后添加自定义标签:
add_filter('woocommerce_variation_price_html','prices_custom_labels', 10, 2 );
add_filter('woocommerce_price_html','prices_custom_labels', 10, 2 );
function prices_custom_labels( $price, $product ){
// Set HERE your custom labels names
$per_dozen = ' '. __('per dozen', 'woocommerce' );
$per_case = ' '. __('per case (20 dozens)', 'woocommerce' );
// 1) Variable products
if ($product->product_type != 'simple' && $product->variation_id ) {
// Getting the array of existing attributes values for a variation
$variation_attribute_value = $product->variation_data;
// Here we keep only the last value in this array
$last_variation_attribute_slug_value = ' ' …Run Code Online (Sandbox Code Playgroud) 对于我的Woocommerce变量产品,我在单个产品页面上实现了自定义大小的选择器,并在表格中具有以下尺寸:
这些变化只是:30B 30C 30D而不是被分成:30和B 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?
我也有woocommerce插件和联系表单7插件.
在产品详细信息页面上,在底部的选项卡中,我有一个名为"查询"的自定义选项卡.我正在嵌入我创建的表单之一.
虽然我只是想在形式上回应产品标题,所以人们不必自己填写.
这似乎不起作用..
<p>Your Name (required)<br />
[text* your-name] </p>
<p>Your Email (required)<br />
[email* your-email] </p>
<p>Subject<br />
</p>
<?php echo get_the_title( 'id' ); ?>
<?php echo WC_Product::get_formatted_name(); ?>
<p>Your Message<br />
[textarea your-message] </p>
<p>[submit "Send"]</p>
Run Code Online (Sandbox Code Playgroud)
有谁有想法吗 ?
提前致谢