تابع ووکامرسی wc_add_to_cart_message افزودن پیغام به سبد خرید اضافه شد

تابع ووکامرسی wc_add_to_cart_message – چگونه پیغام به سبد خرید اضافه شد را ویرایش کنیم .
Syntax – سینتکس
wc_add_to_cart_message( (int|array) $products, (constant) $show_qty = false, (bool) $return = false );
Parameters – پارامتر ها (3)
- 1- $products (int|array)
- 2- $show_qty (constant)
- 3- $return (bool)
Usage – نحوه استفاده
if ( !function_exists( 'wc_add_to_cart_message' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-cart-functions.php';
}
// The products.
$products = null;
// Should qty's be shown? Added in 2.6.0
$show_qty = false;
// Return message rather than add it.
$return = false;
// NOTICE! Understand what this does before running.
$result = wc_add_to_cart_message($products, $show_qty, $return);
Defined – محل تعریف
/includes/wc-cart-functions.php
function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) {
$titles = array();
$count = 0;
if ( ! is_array( $products ) ) {
$products = array( $products => 1 );
$show_qty = false;
}
if ( ! $show_qty ) {
$products = array_fill_keys( array_keys( $products ), 1 );
}
foreach ( $products as $product_id => $qty ) {
$titles[] = ( $qty > 1 ? absint( $qty ) . ' × ' : '' ) . sprintf( _x( '“%s”', 'Item name in quotes', woocommerce ), strip_tags( get_the_title( $product_id ) ) );
$count += $qty;
}
$titles = array_filter( $titles );
$added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', $count, woocommerce ), wc_format_list_of_items( $titles ) );
// Output success messages
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) );
$message = sprintf( '%s %s', esc_url( $return_to ), esc_html__( 'Continue shopping', woocommerce ), esc_html( $added_text ) );
} else {
$message = sprintf( '%s %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', woocommerce ), esc_html( $added_text ) );
}
if ( has_filter( 'wc_add_to_cart_message' ) ) {
wc_deprecated_function( 'The wc_add_to_cart_message filter', '3.0', 'wc_add_to_cart_message_html' );
$message = apply_filters( 'wc_add_to_cart_message', $message, $product_id );
}
$message = apply_filters( 'wc_add_to_cart_message_html', $message, $products );
if ( $return ) {
return $message;
} else {
wc_add_notice( $message );
}
}
versions – نسخه ها
از نسخه : 3.0.2
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر