Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
😊

Hamid Reza Yazdani hamidrezayazdani

😊
View GitHub Profile
@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 ++ ) {
@hamidrezayazdani
hamidrezayazdani / digits-wc-compatibility.php
Created October 12, 2021 23:42
هماهنگی افزونه دیجیتس با محصولات دانلودی ووکامرس
<?php
/**
* Sync wc with DIGITS plugin
*/
function ywp_sync_digits_with_wc( $customer_id, $new_customer_data, $password_generated ) {
$user = get_user_by( 'id', $customer_id );
if ( $user && property_exists( $user, 'user_email' ) && empty( $user->user_email ) ) {
$fake_mail = sprintf(
<?php
function wpp_woodmart_ajax_search_compatibility( $args ) {
if ( function_exists( 'fix_arabic' ) ) {
$args['s'] = fix_arabic( $args['s'] );
}
return $args;
}
@hamidrezayazdani
hamidrezayazdani / show-variation-description-in-single-product.php
Last active October 8, 2021 17:42
نمایش توضیحات آیتم متغیر انتخاب شده محصول متغیر در صفحه محصول ووکامرس
<?php
function ywp_show_variation_description() { ?>
<div id="ywp-var-desc"></div>
<script>
jQuery(function($){
$('form.variations_form').on('show_variation', function (event, data) {
$('#ywp-var-desc').html(data.variation_description);
});
})
<?php
/**
* Change min qty to area
*/
function ywp_set_min_qty_decimal( $val ) {
return 0.1;
}
add_filter('woocommerce_quantity_input_min', 'ywp_set_min_qty_decimal');