【问题标题】:Display custom attributes before WooCommerce upsells ( linked products)在 WooCommerce 追加销售(链接产品)之前显示自定义属性
【发布时间】:2018-01-22 10:53:13
【问题描述】:

我设法显示自定义属性,但它们显示在链接产品之后我怎样才能让它们出现在之前?

左边:我目前拥有的,右边想要的结果

谢谢

【问题讨论】:

  • @LoicTheAztec,感谢您的指导
  • Ok.. 位置已确定,但现在我无法显示帖子的自定义属性,我在 single-product.php 上有这段代码,我已将其移至 mu 函数。 php 文件:add_action('woocommerce_after_single_product_summary', 'custom_code_after_single_product_summary', 12);功能 custom_code_after_single_product_summary() { 全球 $product; // ===> 你的代码在这里 echo '

    Product ID: '。 get_post_meta($post->ID, 'TABLE', true).'

    '; }

标签: php wordpress woocommerce custom-attributes product


【解决方案1】:

如果您查看 woocommerce 模板 content-single-product.php,您会看到:

/**
 * woocommerce_after_single_product_summary hook.
 *
 * @hooked woocommerce_output_product_data_tabs - 10
 * @hooked woocommerce_upsell_display - 15
 * @hooked woocommerce_output_related_products - 20
 */
do_action( 'woocommerce_after_single_product_summary' );

这意味着在 woocommerce_after_single_product_summary 钩子中,会显示以下内容:

  1. 首先(优先级为 10)产品标签,
  2. 然后(优先级为 15)追加销售,
  3. 并完成(优先级为 20)相关产品。

因此,如果您想在产品标签和追加销售之间显示您的自定义代码,您需要使用在 woocommerce_after_single_product_summary 操作挂钩中挂钩的自定义函数,其优先级介于 11 到 14 之间。

你可以这样做:

add_action('woocommerce_after_single_product_summary', 'custom_code_after_single_product_summary', 12 );
function custom_code_after_single_product_summary() {
    global $product;

    // Set here your post "meta_key" for your custom product attribute
    $meta_key1 = 'pa_when-to-use';

    // Your code (related to your comment):
    echo get_post_meta($product->get_id(),  $meta_key1, true);
}

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

在 WooCommerce 3+ 上测试并运行...

【讨论】:

  • Ok.. 位置已确定,但现在我无法显示帖子的自定义属性,我在 single-product.php 上有这段代码: ID,“表”,真); ?>,其中“TABLE”是自定义属性的名称
  • 非常感谢!
  • 这对我有用。谢谢,从我这边投票
猜你喜欢
  • 2017-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
相关资源
最近更新 更多