Viewing 1 post (of 1 total)
  • Author
    Posts
  • Kory Alden
    Participant

    I am trying to display shortcode for the Cart total:

    add_shortcode( ‘quote-total’, ‘get_quote_total’ );
    function get_quote_total(){
    $total = WC()->cart->total;
    $disbursement = 0; // Initializng

    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    if ( has_term( array(‘funeral-types-new’), ‘product_cat’, $cart_item[‘product_id’] ) ) {
    $disbursement += $cart_item[‘line_total’] + $cart_item[‘line_tax’];
    }
    }

    $subtotal = $total – $disbursement;

    return ‘<div>’.wc_price($subtotal).'</div><div> + ‘.wc_price($disbursement).'</div>’;
    }

    // USAGE: [quote-total]
    // or: echo do_shortcode(‘[quote-total]’);

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Subscribe for updates

Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam. View newsletter