Last active
January 24, 2021 13:27
-
-
Save hamidrezayazdani/1a24c5abf38bb3614457c9a160d5736a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
/** | |
* تعیین متن وضعیت سفارشی | |
*/ | |
add_filter( 'woocommerce_get_availability_text', 'ywp_cudtom_get_availability_text', 10, 2 ); | |
function ywp_cudtom_get_availability_text( $availability, $product ) { | |
switch( $product->stock_status ) { | |
case 'my_first_status': | |
$availability = 'وضعیت این محصول در حالت اول است'; | |
break; | |
case 'my_second_status': | |
$availability = 'وضعیت این محصول در حالت دوم است'; | |
break; | |
} | |
return $availability; | |
} | |
/** | |
* مشخص کردن کلاس سی اس اس برای وضعیت جدید | |
*/ | |
add_filter( 'woocommerce_get_availability_class', 'ywo_get_availability_class', 10, 2 ); | |
function ywo_get_availability_class( $class, $product ) { | |
switch( $product->stock_status ) { | |
case 'my_first_status': | |
$class = 'my-first-status'; | |
break; | |
case 'my_second_status': | |
$class = 'my-second-status'; | |
break; | |
} | |
return $class; | |
} | |
/** | |
* غیر فعال کردن افزودن به سبد خرید وقتی وضعیت سفارشی انتخاب میشود | |
*/ | |
add_filter( 'woocommerce_is_purchasable', 'ywp_custom_status_is_purchasable_callback', 10, 2 ); | |
add_filter( 'woocommerce_variation_is_purchasable', 'ywp_custom_status_is_purchasable_callback', 10, 2 ); | |
function ywp_custom_status_is_purchasable_callback( $purchasable, $product ) { | |
if ( $product->get_stock_status() === 'my-first-status' ) { | |
return false; | |
} | |
return $purchasable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment