Last active
July 30, 2019 19:50
-
-
Save mircobabini/928d7b7ff8aa28a49c2f to your computer and use it in GitHub Desktop.
woocommerce useful actions
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
<?php | |
/** | |
* @author Mirco Babini, SED Web Italia | |
* | |
* Contents: | |
* - reset payment method on 'add to cart' | |
* - add message to (customer) email per payment method | |
* - add payment method to email | |
* - remove product tabs | |
* - remove result count and default ordering (doesnt work?) | |
* - move coupon form on checkout | |
* - remove the 'add to cart' button in the shop loop items (archive products) | |
* | |
*/ | |
function woocommerce_edit(){ | |
// reset payment method on 'add to cart' | |
function wc_reset_payment_method(){ | |
global $woocommerce; | |
$woocommerce->session->chosen_payment_method = get_option( 'woocommerce_default_gateway' ); | |
} | |
add_action( 'woocommerce_add_to_cart', 'wp_reset_payment_method', 10, 1 ); | |
// add message to (customer) email per payment method | |
function wc_add_email_message( $order, $is_admin_email ) { | |
if( ! $is_admin_email ){ | |
if( $order->payment_method == 'bacs') { | |
echo 'Custom <b>HTML</b> message here.'; | |
} | |
} | |
} | |
add_action( 'woocommerce_email_before_order_table', 'wc_add_email_message', 3, 2 ); | |
// add payment method to emails | |
function wc_add_payment_method_to_emails( $order, $is_admin_email ) { | |
echo '<p><strong>' . __( 'Payment method', 'woocommerce' ) . ':</strong> ' . $order->payment_method_title . '</p>'; | |
} | |
add_action( 'woocommerce_email_after_order_table', 'wc_add_payment_method_to_emails', 15, 2 ); | |
// remove product tab | |
function wc_remove_reviews_tab( $tabs ){ | |
unset( $tabs['reviews'] ); | |
return $tabs; | |
} | |
add_filter( 'woocommerce_product_tabs', 'wc_remove_reviews_tab', 98 ); | |
// remove result count and default ordering (doesnt work?) | |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); | |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); | |
// move coupon form on checkout | |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); | |
add_action( 'woocommerce_after_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); | |
// remove the 'add to cart' button in the shop loop items (archive products) | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
} | |
add_action('init','woocommerce_edit'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment