Created
January 18, 2019 00:13
-
-
Save MogulChris/ebd694ee1395a9fb1b9763dcc1cb209b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* When using the 'pay for order' link with a WooCommerce Subscriptions renewal order, WCS recreates the order in the cart (setup_cart() in class-wcs-cart-renewal.php) | |
* However it does not copy custom order item meta to the cart items as cart item meta. This has to be done with the filter woocommerce_order_again_cart_item_data | |
*/ | |
function my_custom_add_renewal_cart_item_data($cart_item_data, $line_item, $subscription){ | |
//there will be only one set of cart item data, WCS just packages it as an array for this filter | |
$cart_item_data = array_shift($cart_item_data); | |
if(!empty($cart_item_data['custom_line_item_meta'])){ | |
foreach($cart_item_data['custom_line_item_meta'] as $meta_key => $meta_value){ | |
$cart_item_data[$meta_key] = $meta_value; | |
} | |
} | |
return $cart_item_data; | |
} | |
add_filter('woocommerce_order_again_cart_item_data','my_custom_add_renewal_cart_item_data',10,3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment