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_product_add_to_cart_text', function( $text ) { | |
| global $product; | |
| if ( $product->is_type( 'composite' ) ) { | |
| $text = $product->is_purchasable() ? __( 'Custom options text', 'woocommerce' ) : __( 'Read more', 'woocommerce' ); | |
| } | |
| return $text; | |
| }, 10 ); |
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
| /* Paypal cancel order redirect */ | |
| add_filter( 'woocommerce_get_cancel_order_url_raw', 'paypal_canceled_redirect' ); | |
| function paypal_canceled_redirect(){ | |
| // Replace the URL below with the one you'd like to return to after a canceled order. | |
| return "https://woocommerce.com"; | |
| } |
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
| function is_valid_registration_email_domain( $username, $email, $validation_errors ){ | |
| $valid_email_domains = array( 'gmail.com', 'yahoo.com' ); // Add allowed domains here | |
| $valid = false; // sets default validation to false | |
| foreach( $valid_email_domains as $d ){ | |
| $d_length = strlen( $d ); | |
| $current_email_domain = strtolower( substr( $email, -($d_length), $d_length)); | |
| if( $current_email_domain == strtolower($d) ){ | |
| $valid = true; | |
| break; | |
| } |
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 "Products" to Stripe metadata | |
| */ | |
| function filter_wc_stripe_payment_metadata( $metadata, $order, $source ) { | |
| $count = 1; | |
| foreach( $order->get_items() as $item_id => $line_item ){ | |
| $item_data = $line_item->get_data(); | |
| $product = $line_item->get_product(); | |
| $product_name = $product->get_name(); |
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
| function increase_sf_recent_products( $args ) { | |
| // Sets the maximum products to 14 | |
| $args['limit'] = 14; | |
| // Output | |
| return $args; | |
| } | |
| function remove_powerpack_filter() { |
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_currency_symbol', 'change_existing_currency_symbol', 10, 2); | |
| function change_existing_currency_symbol( $currency_symbol, $currency ) { | |
| if ( ! is_checkout() ) { | |
| return $currency_symbol; | |
| } | |
| switch( $currency ) { | |
| case 'PKR': $currency_symbol = 'PKR'; break; |
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
| // New order notification only for "Pending" Order status | |
| add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 ); | |
| function pending_new_order_notification( $order_id ) { | |
| // Get an instance of the WC_Order object | |
| $order = wc_get_order( $order_id ); | |
| // Only for "pending" order status | |
| if( ! $order->has_status( 'pending' ) ) return; | |
| // Get an instance of the WC_Email_New_Order object |
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_add_to_cart_validation', 'check_num_of_subscriptions', 10, 2); | |
| function check_num_of_subscriptions( $valid, $product_id ) | |
| { | |
| $product_to_add = wc_get_product( $product_id ); | |
| if ( $product_to_add instanceof WC_Product_Subscription || $product_to_add instanceof WC_Product_Variable_Subscription) { | |
| // alternative use: $has_sub = wcs_user_has_subscription( '', '', 'active' ); | |
| if ( has_active_subscription() ) { |
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
| function sd_display_four_home_product_categories( $args ) { | |
| // Displays all product categoris on the homepage of Storefront | |
| $args['limit'] = -1; | |
| // Output | |
| return $args; | |
| } | |
| add_filter( 'storefront_product_categories_args', 'sd_display_four_home_product_categories' ); |
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
| function custom_booking_product_price( $price, $product ) { | |
| $target_product_types = array( | |
| 'booking' | |
| ); | |
| if ( in_array ( $product->product_type, $target_product_types ) ) { | |
| $price = str_replace("From:", "", $price); | |
| return $price; | |
| } | |
| // return normal price | |
| return $price; |