This topic has 7 replies, 2 voices, and was last updated 2 years, 3 months ago ago by Rose Tyler
how i can add shipping class to product page before buttom “shop now”?
I try use this code but no working.
function wpse_295878_shipping_banner() {
$product = wc_get_product();
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case ‘free-shipping’:
echo ‘
‘;
break;
case ‘flat-rate’:
echo ‘
‘;
break;
}
}
add_action( ‘woocommerce_before_single_product’, ‘wpse_295878_shipping_banner’, 20 );
Hello,
Your code needs to be improved
Use next code snippet instead of your one
function etheme_child_product_shipping_banner() {
global $product;
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'free-shipping':
echo 'Free shipping on this item';
break;
case 'flat-rate':
echo 'Flat rate shpping $10';
break;
}
}
add_action('woocommerce_before_single_product', 'etheme_child_product_shipping_banner', 20 );
Result: https://prnt.sc/rLBkW2B8iuG4
Regards
And what name should I enter in: case ‘free-shipping’
When I enter my name it doesn’t work. e.g:
function etheme_child_product_shipping_banner() {
global $product;
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'free-shipping':
echo 'Free shipping on this item';
break;
case 'flat-rate':
echo 'Flat rate shpping $10';
break;
}
}
add_action('woocommerce_before_single_product', 'etheme_child_product_shipping_banner', 20 );
Or maybe it can be done with a static block or custom html code in single product builder?
https://prnt.sc/5HHAnUsAUqxI
my code
function etheme_child_product_shipping_banner() {
global $product;
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'duze-inpost':
echo 'Kurier';
break;
case 'drobnica':
echo 'paczkomat';
break;
}
}
add_action('woocommerce_before_single_product', 'etheme_child_product_shipping_banner', 20 );
Hello,
As we see in the product (1st link from private) you have successfully showed the text for https://prnt.sc/PE1RbLr1cVj4 using our code snippet.
All possible values you may use are here (they are created from your side) -> https://prnt.sc/tUMDPWLRmnRY or you may create new shipping classes and use new ones too.
Example:
function etheme_child_product_shipping_banner() {
global $product;
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'duze-inpost':
echo 'Kurier';
break;
case 'paleta-niestandardowa-dhl':
echo 'paleta-niestandardowa-dhl text';
break;
case 'lekker-niest-bez-pobrania':
echo 'lekker-niest-bez-pobrania custom text';
break;
}
}
add_action('woocommerce_before_single_product', 'etheme_child_product_shipping_banner', 20 );
P.S. Foreach item here -> https://prnt.sc/tUMDPWLRmnRY you may add own special
case 'your-slug':
echo 'your custom text for this shipping class';
break;
We hope, we provided you maximum detalized info about how to achieve your results.
Regards
Or maybe it can be done with a static block or custom html code in single product builder?
https://prnt.sc/5HHAnUsAUqxI
No, please use the method that was described in my previous reply.
Regards
You must be logged in to reply to this topic.Log in/Sign up