• Resolved trothill

    (@trothill)


    Hello,

    Trying to pass the subscription amount from the Woocommerce Subscriptions plugin to the Woocommerce thank you (order-received) page using filter hooks.

    Error_log returns the expected value, but formatted_recurring_amount is returning the default value. Is the code executing in the wrong order, or is there something wrong with my code?

    <?php
    global $recurring_amount;
    $recurring_amount = 1; // Initialize with a default value
    
    add_filter('woocommerce_subscription_price_string', function($subscription_string, $subscription_details) {
        global $recurring_amount;
        $recurring_amount = $subscription_details['recurring_amount'];
    
        error_log('Recurring Amount: ' . $recurring_amount);
    
        return $subscription_string;
    }, 10, 2);
    
    add_filter('woocommerce_get_order_item_totals', 'add_recurring_row_to_totals', 10, 2);
    
    function add_recurring_row_to_totals($total_rows, $order) {
        global $recurring_amount;
    
        $formatted_recurring_amount = isset($recurring_amount) ? wc_price($recurring_amount) : wc_price(0);
    
        $total_rows['recurring_amount'] = array(
            'label' => __('Recurring Amount:', 'woocommerce'),
            'value' => $formatted_recurring_amount,
        );
    
        return $total_rows;
    }
Viewing 1 replies (of 1 total)
  • Plugin Support Rajesh K. (woo-hc)

    (@rajeshml)

    Hello @trothill,

    For reference, this particular forum is meant for general support with the core functionality of WooCommerce itself.  It’s best to ask for insight related to this topic on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Global variables not working in Woocommerce thank you page’ is closed to new replies.