gpt4 book ai didi

php - 在 Woocommerce Force Sells 旁边添加价格

转载 作者:行者123 更新时间:2023-12-05 07:34:58 25 4
gpt4 key购买 nike

默认情况下,Woocommerce Force Sells 仅列出产品标题。我还需要他们在每个标题旁边的括号中显示产品价格。可以看看here就像这个截图:

enter image description here

但应该是:

  • Birth Pool Hire Bond ($50.00)
  • 分娩池衬垫 ($33.00)

是否有我可以使用的过滤器,以便 Force Sells 将价格放在商品旁边?除此之外,我如何更改强制销售代码以使其也输出价格?

这是 Force Sells 代码的一部分,它输出单个产品页面上添加到购物车框下的项目:

    /**
* Displays information of what linked products that will get added when current
* product is added to cart.
*/
public function show_force_sell_products() {
global $post;

$product_ids = $this->get_force_sell_ids( $post->ID, array( 'normal', 'synced' ) );
$titles = array();

// Make sure the products still exist and don't display duplicates.
foreach( array_values( array_unique( $product_ids ) ) as $key => $product_id ) {
$product = wc_get_product( $product_id );

if ( $product && $product->exists() && 'trash' !== $product->get_status() ) {
$titles[] = version_compare( WC_VERSION, '3.0', '>=' ) ? $product->get_title() : get_the_title( $product_id );
}
}

if ( ! empty( $titles ) ) {
echo '<div class="clear"></div>';
echo '<div class="wc-force-sells">';
echo '<p>' . __( 'This will also add the following products to your cart:', 'woocommerce-force-sells' ) . '</p>';
echo '<ul>';

foreach ( $titles as $title ) {
echo '<li>' . $title . '</li>';
}

echo '</ul></div>';
}
}

最佳答案

您可以尝试以下方法:

add_filter( 'woocommerce_product_title', 'custom_product_title', 20, 2 );
function custom_product_title( $name, $product ) {
// Only in single product pages
if( ! is_product() ) return $name;

// The product name + the product formatted price
return $name . ' (' . wc_price( wc_get_price_to_display( $product ) ) . ')';
}

代码进入事件子主题(或事件主题)的 function.php 文件。它应该有效。

关于php - 在 Woocommerce Force Sells 旁边添加价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49871920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com