Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
😊

Hamid Reza Yazdani hamidrezayazdani

😊
View GitHub Profile
@hamidrezayazdani
hamidrezayazdani / ywp_usermeta_in_gravity_from.php
Last active January 9, 2021 17:58
Show User meta as default value in GravityForm
<?php
/**
* GravityForm default user's merge tags doc: https://docs.gravityforms.com/user-merge-tag/
* Sometimes, default merge tags are not enough for us.
* With this snippet you can add custom user meta as a
* new merge tag to gform.
*/
/**
<?php
/**
* اضافه کردن وضعیت موجودی جدید
*/
add_filter( 'woocommerce_product_stock_status_options', 'ywp_custom_product_stock_status' );
function ywp_custom_product_stock_status( $status ) {
$status['my_first_status'] = 'وضعیت جدید اول';
$status['my_second_status'] = 'وضعیت جدید دوم';
return $status;
<?php
add_action( 'wp_footer', 'ywp_goftino_auto_pm' );
function ywp_goftino_auto_pm() {
echo '<script>
if (!localStorage.getItem("goftino_timing") || new Date().getTime() - localStorage.getItem("goftino_timing") >= 60000*24*60){
localStorage.setItem("goftino_timing", new Date().getTime());
localStorage.removeItem("goftino_autopm");
}
</script>';
}
@hamidrezayazdani
hamidrezayazdani / change-add-to-cart-text-for-free-downloadable-products.php
Created February 14, 2021 22:37
تغییر متن دکمه «افزودن به سبد خرید» برای محصولات دانلودی رایگان
<?php
/**
* تغییر متن دکمه «افزودن به سبد خرید» برای محصولات دانلودی رایگان
*/
// تغییر متن دکمه در فروشگاه، دسته و برچسب محصول و صفحات آرکایو
add_filter( 'woocommerce_product_add_to_cart_text', 'ywp_custom_product_add_to_cart_text', 10, 2 );
// تغییر متن دکمه در صفحه محصول
add_filter( 'woocommerce_product_single_add_to_cart_text', 'ywp_custom_product_add_to_cart_text', 10, 2 );
function ywp_custom_product_add_to_cart_text( $add_to_cart_text, $product ) {
if( $product->is_in_stock() && $product->is_downloadable() && $product->get_price() == 0 ) { // محصول موجود، دانلودی و قیمتش صفر باشه
<?php
/**
کد زیر رو به فایل
functions.php
قالبتون اضافه کنید:
**/
/**
* Add calculator Shortcode
*/
# 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;
@hamidrezayazdani
hamidrezayazdani / remove-yoast-social-user-accounts.php
Last active May 16, 2021 03:38
حذف فیلدهای شبکه‌های اجتماعی کاربران یوست برای بهینه بودن جداول مربوط به کاربران
<?php
/**
* خط بالا را کپی نکنید
*
* کد زیر را در آخر فایل
* functions.php
* پوسته خود قبل از
* ?>
* قرار دهید
*/
@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;
<?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();