Попробуйте вместо этого, где $product
(экземпляр объекта WC_Product
) правильно вызывается:
function shortcode_freeshipping( $atts ) {
// Only on single product pages
if( ! is_product() ) return;
// Shortcode attributes
$atts = shortcode_atts( array(
'price' => 8 // HERE you set your default price
), $atts, 'freeshipping' );
global $product;
if( ! is_object($product) )
$product = wc_get_product( get_the_id() );
if( $product->get_price() > $atts['price'] ) {
return __( 'Free Shipping', 'woocommerce' );
} else {
return __( '', 'woocommerce' );
}
}
add_shortcode('freeshipping', 'shortcode_freeshipping');
Код сохраняется в файле function.php вашей активной дочерней темы (или активной темы).Протестировано и работает.
ИСПОЛЬЗОВАНИЕ - 2 варианта:
1) С ценой по умолчанию:
[freeshipping]
2) С индивидуальной ценой(используя аргумент price
):
[freeshipping price="10"]