Ecommerce Shopify WordPress Discussion

Display shortcode content based on the chosen shipping method in WooCommerce cart and checkout

I'm trying to add a custom message based on the shipping method chosen by the customer. Using this code, I was able to do it. The only problem is that I should replace the text part with a shortcode. add_action( 'woocommerce_cart_totals_after_shipping', 'ts_shipping_method_custom_notice' ); add_action( 'woocommerce_review_order_after_shipping', 'ts_shipping_method_custom_notice' ); function ts_shipping_method_custom_notice() { // HERE DEFINE YOUR TARGETED SHIPPING METHOD(S) $targeted_shipping_methods = array('local_pickup:3'); // Replace with the actual shipping method ID(s) // Get the chosen shipping methods $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); if ( ! empty( $chosen_methods ) ) { $chosen_method = reset( $chosen_methods ); // Check if the chosen shipping method is in the targeted list if ( in_array( $chosen_method, $targeted_shipping_methods ) ) { echo '<tr class="shipping"> <td colspan="2" style="text-align:center">' . sprintf( __( "a vit è na briosh", "woocommerce"), '<strong>al 100%</strong>', '<strong>' . WC()->customer->get_shipping_postcode() . '</strong>' ) . '</td> </tr>'; } } }
To display a shortcode, you can use WordPress do_shrotcode() function in the code like: add_action( 'woocommerce_cart_totals_after_shipping', 'display_shipping_method_custom_notice' ); add_action( 'woocommerce_review_order_after_shipping', 'display_shipping_method_custom_notice' ); function display_shipping_method_custom_notice() { $targeted_methods = array('local_pickup:3'); // <== Define the desired shipping method ID(s) $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); if ( ! empty($chosen_methods) ) { // Targeting the chosen shipping method if ( in_array( reset($chosen_methods), $targeted_methods) ) { echo '<tr class="shipping"><td colspan="2" style="text-align:center">' . do_shortcode("[my_shortcode_here]") . '</td></tr>'; } } }

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.