Executing Javascript when a New Post is Published

Your code depends on the post being in an auto-draft state immediately before publication, which isn’t guaranteed. For a more generic option, try using the transition_post_status hook: function display_console_log( $new_status, $old_status, $post ) { // Only runs if the post is transitioning from a not-published state // to the `publish` state. if ( ‘publish’ !== … Read more

Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]

One way to add JavsScript in functions.phhp is to put the JavaScript into a JS file an enqueue it. With wp_enqueue_script(). js/mynicecode.js var x = myFunction(60000, 5.15464, 100); function myFunction(a, b, c) { return Math.round (a * b / c); in functions.php function my_load_scripts($hook) { wp_enqueue_script( ‘mynicecode_js’, plugins_url( ‘js/mynicecode.js’, __FILE__ ), array()); } add_action(‘wp_enqueue_scripts’, ‘my_load_scripts’);