$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>woocommerce offtopic - Adding a widget under an 'Add to Cart' button through a PHP snippet|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far