Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
😊

Hamid Reza Yazdani hamidrezayazdani

😊
View GitHub Profile
@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.
*/
@hamidrezayazdani
hamidrezayazdani / disable-purchasing-instock-products.php
Created June 6, 2023 15:05
Avoid purchasing certain products without them becoming out-of-stock
<?php
/**
* @param $query
* @param $product_id
* @param $exclude_order_id
*
* @return mixed|string
*/
@hamidrezayazdani
hamidrezayazdani / ultimate-member-redirect.php
Created September 4, 2022 19:35
Redirect Comment to Ultimate member Login page on "You must be logged in to post a comment".
<?php
/**
* Change Default Comment Login link to UM Login Page
*/
if ( ! function_exists( 'ywp_um_change_login_link' ) ) {
function ywp_um_change_login_link( $defaults ) {
if ( class_exists( 'UM' ) ) {
$defaults['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), um_get_core_page( 'login' ) ) . '</p>';
return $defaults;
@hamidrezayazdani
hamidrezayazdani / multiple-dropdown-categories.php
Last active September 1, 2022 11:57
Using this class, you can have drop-down lists with "multiple" property.
<?php
defined( 'ABSPATH' ) || exit;
/**
*
*/
class YWP_Walker_CategoryDropdown extends Walker {
/**
* What the class handles.
@hamidrezayazdani
hamidrezayazdani / wc-add-customer-billing-phone-to-review-list.php
Last active July 31, 2022 07:31
Add customer billing phone to review list
<?php
/**
* @param $columns
*
* @return mixed
*/
function ywp_add_billing_phone_column_in_review_list( $columns ): mixed {
$columns['billing_phone'] = __( 'Billing Phone' );