Skip to content

Instantly share code, notes, and snippets.

View madeincosmos's full-sized avatar

Maria Górska-Piszek madeincosmos

View GitHub Profile
@madeincosmos
madeincosmos / functions.php
Created December 4, 2020 10:42
Save categories in order line item metadata
add_action( 'woocommerce_checkout_create_order_line_item', 'custom_checkout_save_category_data_on_the_order', 20, 4 );
function custom_checkout_save_category_data_on_the_order( $item, $cart_item_key, $values, $order ) {
if ( $item->is_type( 'line_item' ) ) {
// Get the product categories for this item
$terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) );
// Save a coma separated string of product category names in line item meta
$item->update_meta_data( 'Categories', implode( ', ', $terms ) );
}
@madeincosmos
madeincosmos / functions.php
Created October 26, 2020 13:06
Simulate PayPal renewal IPN for WooCommerce Subscriptions
add_action( 'woocommerce_order_actions', 'add_simulate_renewal_subscription_action' );
function add_simulate_renewal_subscription_action( $actions ) {
global $theorder;
// Make sure we're in a subscription typeof order
if ( wcs_is_subscription( $theorder ) && ! $theorder->has_status( wcs_get_subscription_ended_statuses() ) ) {
// New action
@madeincosmos
madeincosmos / functions.php
Created August 21, 2020 14:59
Disable currency check in UPS
add_filter ( 'woocommerce_shipping_ups_check_store_currency', '__return_false' );
@madeincosmos
madeincosmos / functions.php
Created August 14, 2020 10:48
Unhook Product Vendor emails from On-Hold status
add_action( 'woocommerce_email', 'unhook_vendor_emails_on_hold_status' );
function unhook_vendor_emails_on_hold_status( $email_class ) {
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Product_Vendors_Order_Email_To_Vendor'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Product_Vendors_Order_Email_To_Vendor'], 'trigger' ) );
}
@madeincosmos
madeincosmos / gist:50debda52e3e9ed3ded6f1683942fa6f
Created July 30, 2020 12:46
Reduce batch size for Square sync
add_filter( 'wc_square_sync_max_objects_to_retrieve', 'custom_reduce_square_batch_size' );
function custom_reduce_square_batch_size( $max ) {
return 200;
}
@madeincosmos
madeincosmos / functions.php
Created February 28, 2020 17:34
Increase product search limit in WP Admin to 100
add_filter ('woocommerce_json_search_limit', 'woo_set_custom_search_limit', 10 );
function woo_set_custom_search_limit( $limit ) {
return 100;
}
@madeincosmos
madeincosmos / functions.php
Created February 5, 2020 13:58
Display 30 points and rewards events on the My Account page
add_filter( 'wc_points_rewards_my_account_points_events', 'custom_points_and_rewards_events_on_my_account_page' );
function custom_points_and_rewards_events_on_my_account_page( $points, $user ) {
return 30;
}
@madeincosmos
madeincosmos / functions.php
Created November 11, 2019 02:55
Check if product add-ons are in cart
add_action( 'woocommerce_before_calculate_totals', 'custom_calculate_shipping_date_based_on_addons' );
function custom_calculate_shipping_date_based_on_addons() {
$cart_contents = WC()->cart->cart_contents;
foreach ( $cart_contents as $cart_item_key => $cart_item_data ) {
if ( ! empty( $cart_item_data['addons'] ) ) {
// addons in cart, add your code here
}
@madeincosmos
madeincosmos / add-email-attachments-for-certain-product.php
Created October 9, 2019 13:42
Add email attachment for certain product only
add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 10, 3 );
function add_woocommerce_attachments_for_certain_product ( $attachments, $email_id, $email_order ){
$product_id = 217762;
$attachment_id = 217944;
if( $email_id === 'customer_processing_order' ){
$order = wc_get_order( $email_order );
$items = $order->get_items();
@madeincosmos
madeincosmos / functions.php
Created October 3, 2019 10:05
Remove PayPal Checkout button from cart
add_action( 'woocommerce_cart_actions', 'custom_remove_paypal_button' );
function custom_remove_paypal_button() {
remove_action( 'woocommerce_proceed_to_checkout', array( wc_gateway_ppec()->cart, 'display_paypal_button' ), 20 );
}