Global variables not working in Woocommerce thank you page
-
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)
Viewing 1 replies (of 1 total)
- The topic ‘Global variables not working in Woocommerce thank you page’ is closed to new replies.