This file contains hidden or 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
/** | |
* Generate a coupon when a specific product is purchased and email it to the customer. | |
* @param AutomateWoo\Workflow $workflow | |
*/ | |
function my_automatewoo_generate_coupon( $workflow ) { | |
$order = $workflow->data_layer()->get_order(); | |
if ( ! $order ) { | |
return; | |
} |
This file contains hidden or 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
/** | |
* Shortcode: [all_attribute_terms attribute="pa_size"] | |
* Shows all terms for a product attribute, even if not assigned to products. | |
* Links use WooCommerce's layered nav filter format. | |
*/ | |
function show_all_attribute_terms( $atts ) { | |
$atts = shortcode_atts( [ | |
'attribute' => '', | |
], $atts ); |
This file contains hidden or 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
add_filter( 'woocommerce_package_rates', 'keep_only_lowest_distance_rate', 20, 2 ); | |
function keep_only_lowest_distance_rate( $rates, $package ) { | |
$lowest_rate_key = ''; | |
$lowest_cost = null; | |
foreach ( $rates as $rate_key => $rate ) { | |
if ( is_null( $lowest_cost ) || floatval( $rate->cost ) < $lowest_cost ) { | |
$lowest_cost = floatval( $rate->cost ); | |
$lowest_rate_key = $rate_key; |
This file contains hidden or 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
add_action( 'woocommerce_cart_calculate_fees', function() { | |
if ( wcs_cart_contains_renewal() ) { | |
return; | |
} | |
$subscription_box_id = 54; | |
$cart_contents = WC()->cart->get_cart_contents(); | |
foreach ( WC()->cart->get_cart() as $cart_item ) { | |
if ( empty( $cart_item[ 'wcsatt_data'][ 'active_subscription_scheme' ] ) ) { | |
continue; | |
} |
This file contains hidden or 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
// Add custom view for products without a vendor | |
add_filter( 'views_edit-product', function( $views ) { | |
$class = ( isset($_GET['no_vendor']) && $_GET['no_vendor'] == 1 ) ? 'current' : ''; | |
$url = add_query_arg( 'no_vendor', '1', admin_url( 'edit.php?post_type=product' ) ); | |
$views['no_vendor'] = "<a href='{$url}' class='{$class}'>No Vendor</a>"; | |
return $views; | |
}); | |
// Modify the query to show products without vendor when selected | |
add_action( 'pre_get_posts', function( $query ) { |
This file contains hidden or 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
add_action( 'woocommerce_order_status_completed', function( $order_id ) { | |
$order = wc_get_order( $order_id ); | |
if ( ! $order ) { | |
return; | |
} | |
foreach ( $order->get_items() as $item ) { | |
$product = $item->get_product(); |
This file contains hidden or 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
add_action( 'admin_enqueue_scripts', function() { | |
remove_action( 'admin_notices', [ 'WC_Bookings_Admin_Install', 'bookable_product_templates_notice' ] ); | |
}); |
This file contains hidden or 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
//Hide the Bundle When a product is Out of Stock | |
add_filter( 'woocommerce_product_is_visible', 'hide_bundle_when_required_product_is_out_of_stock', 10, 2 ); | |
function hide_bundle_when_required_product_is_out_of_stock( $visible, $product_id ) { | |
$product = wc_get_product( $product_id ); | |
// Check if the product is a bundle | |
if ( $product && $product->is_type( 'bundle' ) ) { | |
$bundled_items = $product->get_bundled_items(); |
This file contains hidden or 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
# Inside AutomateWoo, use the variable: {custom_function.aw_get_gift_card_code} to include the gift card code in the email. | |
# The gift card codes are stored as order item meta data. | |
function aw_get_gift_card_code( $workflow ) { | |
$order = $workflow->data_layer()->get_order(); | |
foreach ( $order->get_items() as $item ) { | |
if ( $item->get_product()->is_type( 'gift-card' ) ) { | |
$gift_card_code = $item->get_meta( '_wc_gc_giftcard_code', true ); | |
if ( ! empty( $gift_card_code ) ) { | |
return $gift_card_code; |
This file contains hidden or 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
add_filter( 'woocommerce_email_classes', function( $emails ) { | |
if ( isset( $emails['WC_GC_Email_Gift_Card_Received'] ) ) { | |
unset( $emails['WC_GC_Email_Gift_Card_Received'] ); | |
} | |
return $emails; | |
}, 20 ); |
NewerOlder