以购物车按钮的价格排除产品

时间:2020-04-10 06:50:47

标签: php wordpress woocommerce

我需要你的帮助。我发现可以直接在“添加到购物车”按钮上添加价格。

add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 );
// Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
    // Variable products
    if( $product->is_type('variable') ) {
        // shop and archives
        if( ! is_product() ){
            $product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
            return $button_text . ' - From ' . strip_tags( $product_price );
        } 
        // Single product pages
        else {
            return $button_text;
        }
    } 
    // All other product types
    else {
        $product_price = wc_price( wc_get_price_to_display( $product ) );
        return $button_text . ' - Just ' . strip_tags( $product_price );
    }
}

摘要。有用。如何排除特定产品? “由于使用YITH礼品卡,它仅显示“添加到卡-0€”。

或者,当客户选择特定价格或手动输入价格时,如何用“ Yith礼品卡”显示变动价格?

最简单的方法是隐藏价格,但是直接在按钮上更改价格会很酷。

来源:Display price on add to cart button from the functions.php file in Woocommerce

感谢您的帮助。

0 个答案:

没有答案