شارك المقال

WooCommerce: احصل على معلومات سلة التسوق (الإجمالي ، العناصر ، إلخ) من $ cart Object

A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

بصفتي مستقلاً لتطوير WooCommerce ، أكرر كل يوم العديد من عمليات الترميز التي ما زلت أنسىها مرارًا وتكرارًا!

هذا يعني أنني يجب أن أبحث في ملفات WooCommerce الإضافية مرارًا وتكرارًا وإهدار الكثير من الوقت الثمين.

لقد رأينا بالفعل كيفية الحصول على معلومات المنتج $ و $ من العناصر الخاصة بهما ، لذلك هذه المرة سنلقي نظرة على صفحة سلة التسوق والإجابة على: ” كيفية الحصول على ____ إذا كان لدي متغير / عنصر عربة التسوق $ متوفرة؟ “.

على سبيل المثال ، “كيف يمكنني الحصول على إجمالي سلة التسوق “؟ أو “كيف يمكنني الحصول على عناصر سلة التسوق “؟ أو ربما رسوم عربة التسوق ، والقسائم المطبقة ، وإجمالي محتويات سلة التسوق ، والوزن الإجمالي وما إلى ذلك …

نأمل أن تساعدك هذه المقالة في توفير الوقت أيضًا! إن تعليقاتك عبر Twitter وقسم تعليقات المدونة محل تقدير كبير. يتمتع!

1. إذا كان لديك وصول إلى المتغير $ cart

تستخدم الخطافات (do_action و application_filters) وسيطات إضافية يتم تمريرها إلى الوظيفة. إذا سمحوا لك باستخدام كائن “$ cart” ، فأنت تعمل.

ولكن نظرًا لأن هذا نادر جدًا ، فسننتقل إلى الخطوة 2 على الفور. فقط ضع في اعتبارك أنه إذا كان لديك كائن “$ cart” تحت تصرفك ، فهذا هو بالضبط نفس الكائن “WC () -> cart” ، والذي يمكنك الاتصال به عالميًا في أي قسم أمامي في موقع WooCommerce على الويب.

شيء صغير:

$cart = WC()->cart;

2. إذا لم يكن لديك حق الوصول إلى عربة التسوق $

إذا لم يكن لديك وصول مباشر إلى كائن $ cart ، فيمكنك استدعاؤه عالميًا في أي صفحة من موقع WooCommerce على الويب. هذا هو جمال WC () -> عربة ؛ تستخدم صفحة سلة التسوق هذه الطريقة على سبيل المثال لتحميل عنصر عربة التسوق ، وكذلك يمكنك ذلك في أي مكان تريده.

// $cart conditionals (if)
WC()->cart->is_empty()
WC()->cart->needs_payment()
WC()->cart->show_shipping()
WC()->cart->needs_shipping()
WC()->cart->needs_shipping_address()
WC()->cart->display_prices_including_tax()
 
// Get $cart totals
WC()->cart->get_cart_contents_count();
WC()->cart->get_cart_subtotal();
WC()->cart->subtotal_ex_tax;
WC()->cart->subtotal;
WC()->cart->get_displayed_subtotal();
WC()->cart->get_taxes_total();
WC()->cart->get_shipping_total();
WC()->cart->get_coupons();
WC()->cart->get_coupon_discount_amount( 'coupon_code' );
WC()->cart->get_fees();
WC()->cart->get_discount_total();
WC()->cart->get_total();
WC()->cart->total;
WC()->cart->get_tax_totals();
WC()->cart->get_cart_contents_tax();
WC()->cart->get_fee_tax();
WC()->cart->get_discount_tax();
WC()->cart->get_shipping_total();
WC()->cart->get_shipping_taxes();
  
// Loop over $cart items
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
   $product = $cart_item['data'];
   $product_id = $cart_item['product_id'];
   $quantity = $cart_item['quantity'];
   $price = WC()->cart->get_product_price( $product );
   $subtotal = WC()->cart->get_product_subtotal( $product, $cart_item['quantity'] );
   $link = $product->get_permalink( $cart_item );
   // Anything related to $product, check $product tutorial
   $attributes = $product->get_attributes();
   $whatever_attribute = $product->get_attribute( 'whatever' );
   $whatever_attribute_tax = $product->get_attribute( 'pa_whatever' );
   $any_attribute = $cart_item['variation']['attribute_whatever'];
   $meta = wc_get_formatted_cart_item_data( $cart_item );
}
 
// Get $cart customer billing / shipping
WC()->cart->get_customer()->get_billing_first_name();
WC()->cart->get_customer()->get_billing_last_name();
WC()->cart->get_customer()->get_billing_company();
WC()->cart->get_customer()->get_billing_email();
WC()->cart->get_customer()->get_billing_phone();
WC()->cart->get_customer()->get_billing_country();
WC()->cart->get_customer()->get_billing_state();
WC()->cart->get_customer()->get_billing_postcode();
WC()->cart->get_customer()->get_billing_city();
WC()->cart->get_customer()->get_billing_address();
WC()->cart->get_customer()->get_billing_address_2();
WC()->cart->get_customer()->get_shipping_first_name();
WC()->cart->get_customer()->get_shipping_last_name();
WC()->cart->get_customer()->get_shipping_company();
WC()->cart->get_customer()->get_shipping_country();
WC()->cart->get_customer()->get_shipping_state();
WC()->cart->get_customer()->get_shipping_postcode();
WC()->cart->get_customer()->get_shipping_city();
WC()->cart->get_customer()->get_shipping_address();
WC()->cart->get_customer()->get_shipping_address_2();
 
// Other stuff
WC()->cart->get_cross_sells();
WC()->cart->get_cart_item_tax_classes_for_shipping();
WC()->cart->get_cart_hash();
WC()->cart->get_customer();

المنشورات ذات الصلة:

WooCommerce: كيفية إصلاح مشكلة “السلة فارغة”

WooCommerce: كيفية تحرير أسعار المنتجات بكميات كبيرة؟

توضيح

اي عملية نسخ او اقتباس او ترجمة او نقل تم لاغراض علمية وتدريبية وتعليمية بحته وقد تم انشاء هذا المحتوى بمعرفة خبراء في مجال التقنية اما عن طريق إنشاء او تحرير او نقل او نسخ او اقتباس او ترجمة المحتوى من مصادر خاصة او عامة وكل ذلك ضمن حقوق النشر المتعارف عليها.

اي أخطاء تظهر في المحتوى مهما كان نوعه او تصنيفه يمكنك تحرير رسالة فورية لادارة موثوق لاجل تصحيح هذه الاخطاء، وسنكون شاكرين لك في حال قمت بالتعاون معنا لاجل اصلاح هذه الاخطاء.

أرسل تصحيح

شاركنا رايك وتقييمك للموضوع

{{ reviewsTotal }}{{ options.labels.singularReviewCountLabel }}
{{ reviewsTotal }}{{ options.labels.pluralReviewCountLabel }}
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}