✨1000ج هدية عند تسجيل حساب جديد
🔥خصم حقيقي 15% علي جميع الخدمات 15OFF
🎉مكافآت مالية 10% وخصم 10% لدعوة الأصدقاء
✨1000ج هدية عند تسجيل حساب جديد
🔥خصم حقيقي 15% علي جميع الخدمات 15OFF
🎉مكافآت مالية 10% وخصم 10% لدعوة الأصدقاء
هذا الكود يمكنك من التحكم في زر الطلب وعرض وزن الطلب في سلة التسوق وعلى صفحة مراجعة الطلب في WooCommerce. دعونا نلقي نظرة على كل قسم في الشيفرة:
تعديل زر الطلب بناءً على وزن الطلب:
add_filter( 'woocommerce_order_button_html', 'replace_order_button_html', 10, 2 );
function replace_order_button_html( $order_button ) {
global $woocommerce;
if(WC()->customer->get_billing_country() == 'SA'){
if( $woocommerce->cart->cart_contents_weight < 3 ) return $order_button;
$order_button_text = __( "وزن الطلب يجب ألا يتعدى 3 كجم", "woocommerce" );
$style = ' style="color:#fff;pointer-events: none;cursor:not-allowed;background-color:#999;"';
return '<a class="button alt"'.$style.' name="woocommerce_checkout_place_order" id="place_order" >' . esc_html( $order_button_text ) . '</a>';
}
return $order_button;
}
هذا الجزء يستبدل زر الطلب إذا كان وزن الطلب يتجاوز 3 كيلوغرامات في المملكة العربية السعودية.
عرض وزن الطلب في سلة التسوق وعلى صفحة مراجعة الطلب:
function wcw_cart() {
global $woocommerce;
if ( WC()->cart->needs_shipping() ) : ?>
<tr class="shipping">
<th><?php _e( 'وزن الطلب', 'woocommerce-cart-weight' ); ?></th>
<td><span class="label"><?php echo $woocommerce->cart->cart_contents_weight . ' ' . get_option( 'woocommerce_weight_unit' ); ?></span></td>
</tr>
<?php endif;
}
add_action( 'woocommerce_cart_totals_after_order_total', 'wcw_cart' );
add_action( 'woocommerce_review_order_after_order_total', 'wcw_cart' );
هذا الجزء يقوم بعرض وزن الطلب في سلة التسوق وعلى صفحة مراجعة الطلب. يتم فحص ما إذا كانت الطلبات بحاجة إلى الشحن قبل عرض الوزن.
باستخدام هذا الكود، يمكنك تحكم دقيق في زر الطلب وعرض وزن الطلب في متجر WooCommerce الخاص بك.