Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Created July 25, 2020 16:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrick1229/4aa15cb1bdd06002a833e9b8b4a39dc8 to your computer and use it in GitHub Desktop.
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)
<?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;
}
<?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();
@emranch31
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment