Support & Downloads

Quisque actraqum nunc no dolor sit ametaugue dolor. Lorem ipsum dolor sit amet, consyect etur adipiscing elit.

s f

Contact Info
198 West 21th Street, Suite 721
New York, NY 10010
[email protected]
+88 (0) 101 0000 000
Follow Us

חלב ודבש בניית אתרי אינטרנט

ווקומרס WooCommerce הוספת מס על סה"כ הרכישה כשורת מוצר בסל הקניות

הקוד הבא מציג דרך להסיף מס על סה"כ הרכישה כשורת מוצר בסל הקניות, ולא בסיכון הביניים

  1. יש לפתוח מוצר חדש ולקרוא משם המס לדוגמה "תוספת ליקוט"
  2. יש לסמן במוצר בנראות הקטלוג: חנות ותוצאות חיפוש "להסתיר", בכדי שלא יוצג בחנות
  3. יש להכניס בתחתית קובץ functions.php בתבנית הבת או בתבנית הראשית במידה ואין תבנית בת
  4. לשנות את מספר המוצר בקוד ב $product_id
add_action('woocommerce_checkout_update_order_review', 'add_fee_product');
add_action('woocommerce_checkout_create_order', 'add_fee_product');
add_filter('woocommerce_create_order', 'add_fee_product');
add_action('woocommerce_check_cart_items', 'add_fee_product');

function add_fee_product(){
$product_id = 18896; // מספר פסוט של המוצר
if(check_not_empty_cart($product_id)){
define('FEE_PRODUCT', $product_id);

if( !woo_in_cart($product_id) ){
WC()->cart->add_to_cart($product_id);
}else{
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( $cart_item['product_id'] == $product_id ) {
WC()->cart->remove_cart_item( $cart_item_key );
}
}
WC()->cart->add_to_cart($product_id);
}

global $woocommerce;
$price_reg = 0;
$price_total = 0;
foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];
if($product_id != $_product->id ) {
$price_reg = $_product->get_regular_price() + $price_reg;
$price_total = ($_product->get_regular_price() * $val['quantity']) + $price_total;
}
}

$tax_reg = $price_reg * 0;
$tax_total = $price_total * 0;

foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];
if($product_id == $_product->id ) {
$_product->set_price( $tax_total );
$_product->set_regular_price( $tax_reg );
update_post_meta($_product->id, '_regular_price', (float)$tax_reg);
update_post_meta($_product->id, '_price', (float)$tax_total);
}
}
}else{
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( $cart_item['product_id'] == $product_id ) {
WC()->cart->remove_cart_item( $cart_item_key );
}
}
}

}

function woo_in_cart($product_id) {
global $woocommerce;

foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];

if($product_id == $_product->id ) {
return true;
}
}

return false;
}

function check_not_empty_cart($product_id) {
global $woocommerce;

foreach($woocommerce->cart->get_cart() as $key => $val ) {
$_product = $val['data'];

if($product_id != $_product->id ) {
return true;
}
}

return false;
}