woocommerce offtopic - Adding a widget under an 'Add to Cart' button through a PHP snippet

admin2025-06-03  3

Despite that my PHP knowledge is very scarce I've managed to add some elements under the add-to-cart button in my installation of Woocommerce with the function:

add_action( 'woocommerce_after_add_to_cart_button', 'astra_add_woocommerce_payments', 97 ); 
function astra_add_woocommerce_payments()

I'd like to also add a small currency converter calculator widget using the same function, if possible, but my Google-fu hasn't returned useful results. Do I need to access the source code of the plugin? is there an easy way to do it? where do I start?

Hope to improve my programming skills bit by bit with your help guys. Thanks for your attention.

Despite that my PHP knowledge is very scarce I've managed to add some elements under the add-to-cart button in my installation of Woocommerce with the function:

add_action( 'woocommerce_after_add_to_cart_button', 'astra_add_woocommerce_payments', 97 ); 
function astra_add_woocommerce_payments()

I'd like to also add a small currency converter calculator widget using the same function, if possible, but my Google-fu hasn't returned useful results. Do I need to access the source code of the plugin? is there an easy way to do it? where do I start?

Hope to improve my programming skills bit by bit with your help guys. Thanks for your attention.

Share Improve this question asked Feb 12, 2019 at 23:54 ManjaroDanManjaroDan 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your plugin for the converter supports shortcodes, so this is a good starting point. Everything should be as simple as using this code:

add_action( 'woocommerce_after_add_to_cart_button', 'astra_add_woocommerce_payments', 97 ); 
function astra_add_woocommerce_payments(){
  echo do_shortcode( '[currency_converter_calculator lg=”en” tz=”0″ fm=”EUR” to=”USD” st=”info” bg=”FFFFFF”][/currency_converter_calculator]' );
}

You probably want to wrap the shortcode result inside a div or something to size it properly for your add to cart area.

You can also take the "register sidebar" road and create a proper sidebar/widget area so you can control it from the backend, in that case take a look at this.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748913935a314768.html

最新回复(0)