Quantcast
Channel: تیدا وب
Viewing all articles
Browse latest Browse all 12

دریافت اطلاعات سبد خرید در ووکامرس

$
0
0

در مقالات گذشته درباره دریافت اطلاعات محصول در ووکامرس و دریافت اطلاعات سفارش در ووکامرس مطالبی را بیان کردیم. توابعی دیگری در ووکامرس وجود دارند که می‌توان با استفاده از آن‌ها اطلاعات سبد خرید نظیر مجموع، نام محصول، تعداد و… را دریافت کرد. این توابع کاربردی بوده و در هوک‌ها می‌توان از آن‌ها استفاده نمود. در این نوشته قرار است دریافت اطلاعات سبد خرید در ووکامرس را به شما آموزش دهیم.

توابع کاربردی دریافت اطلاعات سبد خرید در ووکامرس

دسترسی به توابع سبد خرید با استفاده از متغیر cart$

در هوک‌هایی (do_action و یا apply_filters) که استفاده از شی cart$ مجاز است، شما می‌توانید با استفاده از کد زیر به اطلاعات سبد خرید و توابع آن دسترسی داشته باشید.

// Get Cart
$cart = WC()->cart;

دسترسی به توابع سبد خرید بدون استفاده از متغیر cart$

اگر به طور مستقیم به شی cart$ دسترسی ندارید، می‌توانید به طور مستقیم از WC()->cart در هر صفحه از وب‌سایت خود استفاده کنید. 

// $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(); // formatted string $123.99 
WC()->cart->get_total( 'edit' ); // unformatted float 123.99
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'];
    $variation_id = $cart_item['variation_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();

در نوشته بالا، نحوه دریافت اطلاعات سبد خرید در ووکامرس را به شما آموزش دادیم. در صورتی که سوالی داشتید آن را با ما از طریق دیدگاه‌ها در میان بگذارید.

منبع: Business Bloomer

۴.۸/۵ - (۶۳ امتیاز)

نوشته دریافت اطلاعات سبد خرید در ووکامرس اولین بار در تیدا وب. پدیدار شد.


Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles



Latest Images