Created
August 6, 2017 18:56
-
-
Save davebonds/8b42184a0c466ef76b529b7837663f3c 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 | |
/** | |
* Add line item for monthly ad budget set by customer. | |
* Added as $0 - will be adjusted in subscription later based on actual spend. | |
* | |
* @param obj $item Passed by reference. | |
* @param str $cart_item_key Cart key. | |
* @param arr $values Cart values. | |
* @param obj $order Order object. | |
*/ | |
public function add_order_ad_budget_item( $item, $cart_item_key, $values, $order ) { | |
// If value is set then create new fee item object and add item. | |
if( isset( $values['sem-ad-budget'] ) ) { | |
// Add value as meta data to product in order prefixed with dollar sign. | |
$item->add_meta_data('sem_ad_budget', '$' . $values['sem-ad-budget']); | |
// Create new Fee object. | |
$fee_item = new WC_Order_Item_Fee(); | |
// Set item props. Set total to 0 for later adjustment. | |
$fee_item->set_props( array( | |
'name' => 'Monthly Ad Budget - $' . $values['sem-ad-budget'], | |
'tax_class' => 0, | |
'total' => 0, | |
'total_tax' => 0, | |
'taxes' => array( | |
'total' => 0, | |
), | |
) ); | |
// Add the fee as a line item. | |
$order->add_item( $fee_item ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment