Home > Software engineering >  How to add a custom shortcode below the product table on woocommerce checkout page
How to add a custom shortcode below the product table on woocommerce checkout page

Time:11-01

Problem:
I need to add a shortcode [wc_sc_available_coupons] below the product table on the checkout page.
I added the following code in functions.php
The problem is the shortcode displays at the very bottom of the checkout form.
I changed the number 10 to 120 but still the same.
Would you please let me know how to add the shortcode below the product table (=above the payment)?

Code I tried:

add_action( 'woocommerce_after_checkout_form', 'wnd_checkout_code', 10 );

function wnd_checkout_code( ) {
  echo do_shortcode('[wc_sc_available_coupons]');
}

Thank you.

CodePudding user response:

Would woocommerce_checkout_after_customer_details hook work for you? So your code would be something like this:

add_action( 'woocommerce_checkout_after_customer_details', 'wnd_checkout_code' );

function wnd_checkout_code( )
{
  echo do_shortcode('[wc_sc_available_coupons]');
}

If not then you could try other hooks such as woocommerce_checkout_before_order_review or you could try this woocommerce_before_order_notes as well.

This one is right before the payment:

add_action( 'woocommerce_review_order_before_payment', 'wnd_checkout_code' );

function wnd_checkout_code( ) 
{
  echo do_shortcode('[wc_sc_available_coupons]');
}

CodePudding user response:

Use the action:

add_action("woocommerce_after_cart_table", $action)

OR

add_action("woocommerce_before_cart_collaterals", $action)

Result https://imgur.com/a/zQVNedb


In general for WooCommerce you can find hook info here: https://woocommerce.github.io/code-reference/hooks/hooks.html

and for your template: https://woocommerce.github.io/code-reference/files/woocommerce-templates-cart-cart.html#source-view.159

You can see information on the actions allowed by looking at the source code in woocommerce/templates/ and checking the do_action() functions.

  • Related