Created
July 25, 2020 16:41
-
-
Save jrick1229/4aa15cb1bdd06002a833e9b8b4a39dc8 to your computer and use it in GitHub Desktop.
Output the 'purchase note' of a product with a variable in AutomateWoo. (currently only works with one product per order)
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 the new variable to the list. | |
*/ | |
add_filter( 'automatewoo/variables', 'new_automatewoo_purchase_note_variable' ); | |
/** | |
* @param $variables array | |
* @return array | |
*/ | |
function new_automatewoo_purchase_note_variable( $variables ) { | |
$variables['order']['purchase_note'] = dirname(__FILE__) . '/product-purchase-note.php'; | |
return $variables; | |
} |
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 | |
/** | |
* Place this file directly within your theme's main folder. | |
* eg, /wp-content/themes/storefront/product-purchase-note.php | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
/** | |
* @class New_AutomateWoo_Variable_Purchase_Note | |
*/ | |
class New_AutomateWoo_Variable_Purchase_Note extends AutomateWoo\Variable { | |
protected $name = 'order.purchase_note'; | |
function load_admin_details() { | |
$this->description = __( 'Display the purchase note of a particular product.', 'automatewoo'); | |
parent::load_admin_details(); | |
} | |
function get_value( $order, $parameters ) { | |
$items = $order->get_items(); | |
foreach ( $items as $item ) { | |
$product = $order->get_product_from_item( $item ); | |
$purchase_note = get_post_meta( $product->id, '_purchase_note', true ); | |
return $purchase_note; | |
} | |
} | |
} | |
return new New_AutomateWoo_Variable_Purchase_Note(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you help me with something ?
i have an issue of automate-woo refer a friend
I am trying to set prefix for coupon to empty string but validation is not working