Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
🤕

Hamid Reza Yazdani hamidrezayazdani

🤕
View GitHub Profile
@hamidrezayazdani
hamidrezayazdani / replace_persian_arabic_numbers_in_metadata.php
Created August 1, 2021 21:16
This snippet convert persian/arabic numbers to english numbers in metadata
<?php
/**
* Convert numbers to english
*
* @param $input
*
* @return array|string
*/
function ywp_convert_numbers_to_latin( $input ): array|string {
$arabic = [ '٩', '٨', '٧', '٦', '٥', '٤', '٣', '٢', '١', '٠' ];
@hamidrezayazdani
hamidrezayazdani / show-visual-editor-in-admin-taxonomies-pages.php
Last active May 24, 2024 07:17
Activate the visual editor in admin taxonomies pages
<?php
$taxonomies = array(
'category', // for posts categories
'post_tag', // for posts tags
'product_tag', // for wc products tags
'product_cat', // for wc products categories
'product_brand', // for woocommerce brand plugin
'brand', // for yith product brand
@hamidrezayazdani
hamidrezayazdani / add-custom-field-to-wc-register-form.php
Last active June 22, 2021 08:26
Add first & last name fields to woocommerce registration form
<?
/**
* Add a custom field to woocommerce registeration form
*/
add_action( 'woocommerce_register_form', 'ywp_add_name_field_ro_wc_register_form' );
function ywp_add_name_field_ro_wc_register_form() {
woocommerce_form_field(
'ywp_register_fname',
array(
'type' => 'text',
<?php
/**
* add shortcode to wp
*/
add_shortcode( 'stock_status', 'display_product_stock_status' );
function display_product_stock_status( $atts) {
$atts = shortcode_atts(
array('id' => get_the_ID() ),
$atts,
<?php
/**
* Change "Add to cart" button text
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'ywp_override_add_to_cart_text', PHP_MAX_INT );
add_filter( 'woocommerce_product_add_to_cart_text', 'ywp_override_add_to_cart_text', PHP_MAX_INT );
function ywp_override_add_to_cart_text() {
return 'ثبت سفارش';
}
<?php
/**
* Show weight and dementions end of additional information
*/
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_product_additional_information', 'ywp_display_product_attributes', 10 );
function ywp_display_product_attributes( $product ) {
$product_attributes = array();
@hamidrezayazdani
hamidrezayazdani / remember-me-for-one-year.php
Last active June 2, 2021 14:17
Wordpress remember me cookie lifetime
<?php
/**
* Hook on auth_cookie_expiration
* The code goes in your theme/child theme functions.php
* You can also use this plugin: https://wordpress.org/plugins/code-snippets/
*/
add_filter ( 'auth_cookie_expiration', 'ywp_change_remember_me' );
function ywp_change_remember_me( $expire ) {
return YEAR_IN_SECONDS;
@hamidrezayazdani
hamidrezayazdani / remove-yoast-social-user-accounts.php
Last active May 16, 2021 03:38
حذف فیلدهای شبکه‌های اجتماعی کاربران یوست برای بهینه بودن جداول مربوط به کاربران
<?php
/**
* خط بالا را کپی نکنید
*
* کد زیر را در آخر فایل
* functions.php
* پوسته خود قبل از
* ?>
* قرار دهید
*/
# For posts categories
SELECT t.term_id AS id,
t.name AS 'Term Title',
t.slug AS 'Slug'
FROM wp_terms t
LEFT JOIN wp_term_taxonomy tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'category'
ORDER BY name;