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( 'gettext', 'rename_length_to_depth', 20, 3 ); | |
| function rename_length_to_depth( $translated_text, $untranslated_text, $domain ) { | |
| if ( $untranslated_text == 'Length' && $domain == 'woocommerce' ) { | |
| $translated_text = 'Depth'; | |
| } | |
| return $translated_text; | |
| } |
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
| // Register the shortcode [dimensiondisplay] Replace 'dimensiondisplay' below with preferred shortcode name. | |
| add_shortcode( 'dimensiondisplay', 'dimension_display_shortcode' ); | |
| // Shortcode callback function | |
| function dimension_display_shortcode() { | |
| global $product; | |
| // Get the dimensions attribute value. Replace 'dimensions' with relevant attribute name. | |
| $dimensions = $product->get_attribute( 'dimensions' ); |
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 Name Your Price Field on Cart page | |
| add_filter( 'woocommerce_cart_item_price', 'add_name_your_price_field_to_cart', 10, 3 ); | |
| function add_name_your_price_field_to_cart( $product_price, $cart_item, $cart_item_key ) { | |
| global $woocommerce; | |
| // Check if the Name Your Price plugin is active and if the current product supports it | |
| if ( class_exists( 'WC_Name_Your_Price' ) && WC_Name_Your_Price_Helpers::product_supports_name_your_price( $cart_item['data'] ) ) { | |
| // Add Name Your Price Field | |
| $name_your_price_input = woocommerce_name_your_price_input( $cart_item['product_id'], '', '', false ); |
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
| //Skip Cart & Redirect To Checkout | |
| add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' ); | |
| function custom_add_to_cart_redirect() { | |
| global $woocommerce; | |
| $checkout_url = $woocommerce->cart->get_checkout_url(); | |
| return $checkout_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
| //This code snippet will search through the order notes for the words 'Loren ipsum' and then display that note in the Order Completed Email sent to a customer. | |
| function action_woocommerce_email_order_details( $order, $sent_to_admin, $plain_text, $email ) { | |
| // Target specific email notification | |
| if ( $email->id == 'customer_completed_order' ) { | |
| // Get order id | |
| $order_id = $order->get_id(); | |
| // Get order notes | |
| $order_notes = wc_get_order_notes( array( |
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
| The snippets below adds an action hook that listens for incoming webhook requests. When a webhook request is received, the code retrieves the order ID from the metadata sent with the webhook. It then checks if the order exists and the payment has not already been marked as completed. If these conditions are met, the code updates the order status to "completed" using the update_status() method of the 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 a new menu item to the WordPress admin menu | |
| function add_australian_sales_menu_item() { | |
| add_menu_page( | |
| 'Australian Sales', // Page title | |
| 'Australian Sales', // Menu title | |
| 'manage_options', // Capability required to access the page | |
| 'australian-sales', // Menu slug | |
| 'display_australian_sales_page' // Callback function that displays the 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
| //This code will fail the checkout process with a custom message. The order time and products that were attemtpted to be purchased will be logged to a text file in wp/content and the log will be displayed under Checkout Log in the wordpress Dashboard. | |
| // Add custom admin page | |
| add_action('admin_menu', 'auto_fail_custom_admin_page'); | |
| function auto_fail_custom_admin_page() { | |
| add_menu_page( | |
| 'Checkout Log', | |
| 'Checkout Log', | |
| 'manage_options', | |
| 'checkout-log', |
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
| <script> | |
| // This code allows users to switch between the first variation of a product regardless of whether the second variation selection is availaible for that combination. This works by displaying all combinations for the first variation. If a particular combination is not availaible for the first selected variation a message will be displayed and the second variation will be reset. Credit to user : https://stackoverflow.com/users/10755574/intelligent-web-solution for the original solution. | |
| jQuery(document).ready(function($){ | |
| if (jQuery('form.variations_form').length) { | |
| let $form = jQuery('form.variations_form'); | |
| let $first_attr_select = $form.find( '.variations select' ).eq(0); | |
| let first_attr_val = $first_attr_select.val() || ''; | |
| $first_attr_select.on('change', function(e){ |
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 empty categories from 'customer' usergroup & non logged in users. Display to everyone else. | |
| add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_categories_for_logged_in_users', 999 ); | |
| function show_categories_for_logged_in_users( $hide_empty ) { | |
| //change'customer' to match needed usergroup | |
| if ( is_user_logged_in() && ! current_user_can( 'customer' ) ) { | |
| $hide_empty = false; | |
| } | |
| return $hide_empty; | |
| } |