Skip to content

Instantly share code, notes, and snippets.

View shameemreza's full-sized avatar
🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset

Shameem Reza shameemreza

🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset
View GitHub Profile
@shameemreza
shameemreza / hide-cancel-subscription-button-on-user-dashboard.php
Created July 6, 2024 17:23
Hide cancel subscription button on user dashboard in WooCommerce.
add_filter('wcs_view_subscription_actions', 'delay_user_action_cancel_button', 10, 3 );
function delay_user_action_cancel_button( $actions, $subscription, $user_id ) {
// Check that 'cancel' action button is active
if ( ! isset($actions['cancel']) ) return $actions;
$start_date = $subscription->get_date('start'); // Get the start date
$days_period = 15; // Here define the "designated time limit" in days
if ( strtotime($start_date) + ( $days_period * DAY_IN_SECONDS ) >= time() ) {
@shameemreza
shameemreza / delete-product-images-after-deleting.php
Created July 3, 2024 08:41
Delete Woocommerce images after deleting product
// Automatically Delete Woocommerce Images After Deleting a Product
add_action( 'before_delete_post', 'delete_product_images', 10, 1 );
function delete_product_images( $post_id ) {
// Check if user has the capability to delete products
if ( !current_user_can( 'delete_products' ) ) {
return;
}
$product = wc_get_product( $post_id );
@shameemreza
shameemreza / automatewo-custom-funcitons-variable.php
Created June 27, 2024 04:33
AutomateWoo Custom Function action with Variable.
function my_function_name() {
$workflow = AutomateWoo\Workflows::get_current();
if ( $workflow ) {
$customer_id = $workflow->data_layer()->get_customer_id();
// Now you can use $customer_id in your function
}
}
add_action( 'automatewoo/custom_functions', 'my_function_name' );
@shameemreza
shameemreza / woo-forum-highlighter-org.js
Last active June 20, 2024 02:09
Woo Forum Highlighter for .org
// ==UserScript==
// @name Woo Forum Highlighter for .org
// @namespace https://woocommerce.com/
// @version 1.0.28
// @description Highlight threads where an a11n was the last to reply.
// @match https://wordpress.org/support/plugin/*
// @match https://wordpress.org/support/theme/*
// @match https://wordpress.org/support/users/*
// @match https://*.wordpress.org/plugins/*
// @downloadURL https://github.com/Automattic/support-helper-tools/raw/main/woocommerce-tools/wcforumattic.user.js
@shameemreza
shameemreza / display_striked_out_price_for_variable.php
Created June 12, 2024 10:31
Show Striked Out Price Range for Variable Products in WooCommerce
add_filter('woocommerce_get_price_html', 'display_striked_out_price_for_variable', 200, 2);
function display_striked_out_price_for_variable($price='', $product)
{
if (!$product->is_on_sale()){
return $price;
}
if ($product->is_type('variable')) {
$variations = $product->get_available_variations();
$regular_prices = array();
$sale_prices = array();
@shameemreza
shameemreza / restore-price-suffix-variable-product-woocommerce.php
Created May 30, 2024 02:52
Restore price suffix for variable product in WooCommerce
add_filter('woocommerce_get_price_suffix', function ( $html, $product, $price, $qty ) {
if ( ! $html && $product instanceof WC_Product_Variable) {
// Copied from plugins/woocommerce/includes/abstracts/abstract-wc-product.php#get_price_suffix
if ( ( $suffix = get_option( 'woocommerce_price_display_suffix' ) )
&& wc_tax_enabled()
&& 'taxable' === $product->get_tax_status()
) {
$replacements = array(
'{price_including_tax}' => wc_price( wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
'{price_excluding_tax}' => wc_price( wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
@shameemreza
shameemreza / remove-quantity-field-single-product.php
Created May 28, 2024 10:28
Remove the quantity field for ALL of your WooCommerce products
function custom_remove_all_quantity_fields( $return, $product ) {
return true;
}
add_filter ( 'woocommerce_is_sold_individually','custom_remove_all_quantity_fields', 10, 2 );
@shameemreza
shameemreza / remove-sidebar-storefront-theme.php
Created May 20, 2024 08:13
Remove Sidebar on Single Product Page for Storefront Theme
add_action( 'get_header', 'srdev_remove_storefront_sidebar' );
function srdev_remove_storefront_sidebar() {
if ( is_product() ) {
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
}
}
@shameemreza
shameemreza / remove-additional-information-tab.php
Last active May 8, 2024 09:28
Remove the Additional Information tab from the WooCommerce single product pages
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 98 );
function remove_additional_information_tab( $tabs ) {
// Check if the 'additional_information' tab is set and remove it
if (isset($tabs['additional_information'])) {
unset($tabs['additional_information']);
}
return $tabs;
}
@shameemreza
shameemreza / gutenberg-block-editor-support-to-woocommerce.php
Last active May 8, 2024 09:43
Add Gutenberg Editor support to WooCommerce Classic Editor
// enable gutenberg for woocommerce
function activate_gutenberg_product( $can_edit, $post_type ) {
if ( $post_type == 'product' ) {
$can_edit = true;
}
return $can_edit;
}
add_filter( 'use_block_editor_for_post_type', 'activate_gutenberg_product', 10, 2 );
// enable taxonomy fields for woocommerce with gutenberg on