Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hamidrezayazdani/f8a71efb0ff468ac25fd4cb9bc74af64 to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/f8a71efb0ff468ac25fd4cb9bc74af64 to your computer and use it in GitHub Desktop.
تغییر متن دکمه «افزودن به سبد خرید» برای محصولات دانلودی رایگان
<?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 ) { // محصول موجود، دانلودی و قیمتش صفر باشه
return 'دانلود';
}
return $add_to_cart_text; // متن پیشفرض رو برمیگردونیم
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment