Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
🤕

Hamid Reza Yazdani hamidrezayazdani

🤕
View GitHub Profile
@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' );
@hamidrezayazdani
hamidrezayazdani / prevent-wp-from-create-redirect.php
Created December 23, 2021 13:17
جلوگیری از ریدایرکت توسط وردپرس
<?php
/**
* Prevent wordpress from redirect deleted posts
*/
remove_action( 'template_redirect', 'wp_old_slug_redirect' );
remove_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 );
add_filter( 'redirect_canonical', '__return_false' );
@hamidrezayazdani
hamidrezayazdani / Allow-HTML-in-terms-descriptions.php
Created December 3, 2021 22:07
Allow HTML in term (category, tag) descriptions
<?php
/**
* Allow HTML in term (category, tag) descriptions
*/
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
if ( ! current_user_can( 'unfiltered_html' ) ) {
add_filter( $filter, 'wp_filter_post_kses' );
}
@hamidrezayazdani
hamidrezayazdani / woocommerce-set-minimum-qty.php
Created October 30, 2021 23:50
تعیین حداقل تعداد دو عدد از محصول در هنگام خرید
<?php
/**
* Change the minimum quantity to 2
*/
function ywp_wc_quantity_input_min_callback( $min, $product ) {
return 2;
}
add_filter( 'woocommerce_quantity_input_min', 'ywp_wc_quantity_input_min_callback', 10, 2 );
@hamidrezayazdani
hamidrezayazdani / wc-redirect-to-previouse-page-after-login.php
Last active October 23, 2021 17:21
انتقال کاربر ووکامرس به صفحه قبلی پس از ورود موفق به حساب کاربری
<?php
/**
* Redirect to previous location after login.
*/
function ywp_login_redirect( $redirect, $user ) {
return $_SERVER['HTTP_REFERER'];
}
add_filter( 'woocommerce_login_redirect', 'ywp_login_redirect', 1100, 2 );
@hamidrezayazdani
hamidrezayazdani / woocommerce-custom-successful-payment.php
Last active October 15, 2021 18:45
پیام تبریک سفارشی در صفحه تشکر از خرید ووکامرس پس از پرداخت موفق
<?php
/**
* Change WooCommerce thank you message after successful payment
*/
function ywp_custom_wc_thankyou_notice( $order ) {
return 'از خرید شما سپاسگزاریم، از لیست زیر می‌توانید فایل‌های خریداری شده را دانلود کنید.';
}
add_filter( 'woocommerce_thankyou_order_received_text', 'ywp_custom_wc_thankyou_notice' );
@hamidrezayazdani
hamidrezayazdani / nofollow-specific-domain.php
Last active October 15, 2021 18:47
نوفالو کردن لینک های خارجی پیکوفایل
<?php
/**
* Add "nofollow" to picofile external links
*/
function ywp_nofollow_picofile_extrenal_links( $content ) {
$domain = "https://www.picofile.com";
preg_match_all( '~<a.*>~isU', $content, $matches );
for ( $i = 0; $i <= count( $matches[0] ); $i ++ ) {