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( 'template_redirect', 'wc_custom_redirect_after_purchase' ); | |
| function wc_custom_redirect_after_purchase() { | |
| global $wp; | |
| if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) { | |
| $order_id = absint( $wp->query_vars['order-received'] ); | |
| $order_key = wc_clean( $_GET['key'] ); | |
| /** | |
| * Replace {PAGE_ID} with the ID of your page |
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
| // Automatically grant membership at registration | |
| function sv_add_membership_at_registration( $user_id ) { | |
| $args = array( | |
| // Enter the ID (post ID) of the plan to grant at registration | |
| 'plan_id' => 253, | |
| 'user_id' => $user_id, | |
| ); | |
| wc_memberships_create_user_membership( $args ); | |
| } | |
| add_action( 'user_register', 'sv_add_membership_at_registration', 15 ); |
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
| $args = array( | |
| // Enter the ID (post ID) of the plan to grant access to | |
| 'plan_id' => 253, | |
| 'user_id' => $user_id, | |
| ); | |
| wc_memberships_create_user_membership( $args ); |
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( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' ); | |
| function wc_subs_suspend_on_cod( $order ) { | |
| if ( ! is_object( $order ) ) { | |
| $order = new WC_Order( $order ); | |
| } | |
| foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) { | |
| $subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) ); |
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
| // Get current user ID | |
| $user_id = get_current_user_id(); | |
| // Check if the user is member of the plan 'gold' | |
| if ( wc_memberships_is_user_active_member( $user_id, 'gold' ) ) { | |
| echo 'This is a special message only for Gold members!'; | |
| } else { | |
| echo 'I\'m sorry, you are not a gold member. There's nothing here for you!'; | |
| } |
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
| // Enable WP_DEBUG mode | |
| define('WP_DEBUG', true); | |
| // Enable Debug logging to the /wp-content/debug.log file | |
| define('WP_DEBUG_LOG', true); | |
| // Disable display of errors and warnings | |
| define('WP_DEBUG_DISPLAY', false); | |
| @ini_set('display_errors',0); |
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
| // remove a column | |
| function wc_csv_export_remove_column( $column_headers ) { | |
| // the list of column keys can be found in class-wc-customer-order-csv-export-generator.php | |
| unset( $column_headers['coupon_items'] ); | |
| return $column_headers; | |
| } | |
| add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' ); |
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
| // remove a column | |
| function wc_csv_export_remove_column( $column_headers ) { | |
| // the list of column keys can be found in class-wc-customer-order-csv-export-generator.php | |
| unset( $column_headers['coupon_items'] ); | |
| return $column_headers; | |
| } | |
| add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' ); |
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
| /** | |
| * Changes the redirect URL for the Return To Shop button in the cart. | |
| * | |
| * @return string | |
| */ | |
| function wc_empty_cart_redirect_url() { | |
| return $_SERVER['HTTP_REFERER']; | |
| } | |
| add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' ); |
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
| /** | |
| * Print the product's vendor name before the product title in the loop. | |
| * | |
| * @return void | |
| */ | |
| function wc_vendors_name_loop() { | |
| $vendors = get_the_terms( get_the_ID(), 'shop_vendor' ); | |
| if ( $vendors && ! is_wp_error( $vendors ) ) { | |
| foreach ( $vendors as $vendor ) { |