Home Improve the code for print json data
Reply: 0

Improve the code for print json data

user746 Published in April 22, 2018, 10:01 pm
function add_price_calculate_tour() {
  global $post;
  $product = wc_get_product( $post->ID );
  if( $product->is_type( 'tour_booking' ) ):

    $priceAdult = (float) get_post_meta( $product->get_id(), '_regular_price', true );
    $priceChild = (float) get_post_meta( $product->get_id(), 't_children_price', true );

    $tour = json_encode(["priceAdult" => $priceAdult,"priceChild" => $priceChild]);
    wp_add_inline_script( 'twentyseventeen-global', 'var tour = '.$tour.'', 'before' );


I would like to simplify or improve this code, what it does basically is to create an array with a value, and then create a json and print it in the footer.

Any suggestions?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303632 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO