Search code examples
phpwordpresswoocommercehook-woocommerceshortcode

How to add a custom shortcode below the product table on woocommerce checkout page


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.


Solution

  • 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]');
    }