Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
🤕

Hamid Reza Yazdani hamidrezayazdani

🤕
View GitHub Profile
@hamidrezayazdani
hamidrezayazdani / add-slug-to-attribute-search-result.php
Created January 25, 2025 20:02
Add the slug to attribute selectbox in the WooCommerce product editing page
<?php
/**
* When you have a lot of values in an attribute and some of them have similar names,
* choosing the right value in the attribute field in the product information box is a pain and there is a high chance of mistakes.
* One solution is to consider a different slug for each attribute.
* But the problem is that when searching for values in attributes,
* only the attribute name is displayed to you.
* The code that follows helps you choose the right values by displaying the slug of each value (after its name).
*/
@hamidrezayazdani
hamidrezayazdani / force-to-refresh-users-browser-cache-for-specific-wc-product.php
Created July 23, 2024 11:05
Force refresh users browser cache for specefic Yoast deleted product redirect
<?php
/**
* Clearing the browser cache for all users who have visited your site can be challenging
* since you can’t directly control their browsers.
* However, you can take some steps to ensure that the updated URL is served to everyone
*/
/**
* Force refresh users browser cache for specefic Yoast deleted product redirect
<?php
function ywp_fix_woocommerce_admin_order_list_css() {
$custom_css = "
@media screen and (max-width: 782px) {
.post-type-shop_order .wp-list-table tr:not(.is-expanded) td.column-order_number a.order-view, .woocommerce_page_wc-orders .wc-orders-list-table.wp-list-table tr:not(.is-expanded) td.column-order_number a.order-view {
width: calc(100% - 48px - 10ch)!important;
}
}
@hamidrezayazdani
hamidrezayazdani / better-order-editing-page.php
Last active June 16, 2024 07:46
Adding row numbers and distinguishing lines of order items to the order editing page in WooCommerce for a better order editing experience
<?php
/**
* Add row numbers to order items in admin edit order page
*/
function ywp_better_admin_order_editing_items() {
$current_screen = get_current_screen();
if ( empty( $current_screen ) || ! property_exists( $current_screen, 'id' ) ) {
return;
}
@hamidrezayazdani
hamidrezayazdani / finding-class-shipping-id.jpg
Last active December 4, 2023 12:11
Hide specific shipping method if a shipping class is showing
finding-class-shipping-id.jpg
@hamidrezayazdani
hamidrezayazdani / speedup-woocommerce-search-in-admin-area.php
Created November 26, 2023 14:02
Speedup WooCommerce admin area orders search
<?php
/**
* When you have many orders, searching in the WooCommerce admin section will be very slow.
* The reason is that WooCommerce looks for the search term in many fields of the order
* (such as billing address and shipping address).
* With the following code, you can search only the metas you need.
* For me, only the first name and last name were important.
* Of course, the search will still be done based on the phone number, email and order number,
* and there will be no problem in the main function.
@hamidrezayazdani
hamidrezayazdani / change-order-on-edit-product-screen.php
Last active November 18, 2023 14:34
Change WooCommerce order by condition on the edit product screen.
<?php
/**
* Change views on the edit product screen.
*
* @param array $views Array of views.
* @return array
*/
function ywp_product_views( $views ) {
global $wp_query;
@hamidrezayazdani
hamidrezayazdani / post-reading-time.php
Last active November 15, 2023 06:24
Post reading time
<?php
function ywp_reading_time() {
global $post;
if ( empty( $post ) ) {
$post = get_the_ID();
}
if ( empty( $post ) ) {
@hamidrezayazdani
hamidrezayazdani / filter-orders-by-payment-methods.php
Created June 21, 2023 07:47
Filter WooCommerce orders by payment methods in admin panel
<?php
/**
* Create a list of all available payment methods, even inactive ones
*
* @return void
*/
function ywp_filter_orders_by_payment_method() {
global $typenow;
@hamidrezayazdani
hamidrezayazdani / change-boxed-products-price-in-cart-and-checkout.php
Last active June 20, 2023 09:47
Add single product price for variable boxed products in the cart and checkout
<?php
/**
* prerequisites:
* You must define products as variables. One variation for single purchase and one variation for box purchase.
*
* You can change the name of the box purchase attribute in the code below. (the 'box-capacity' variable).
* For each variation, you set one equal to the number 1 for the other variation equal to the number in each box.
*
* Copy the following code into the functions.php file of the theme/child theme.
*/