تابع ووکامرسی wc_product_post_class افزودن کلاس های html اضافی به محصول

تابع ووکامرسی wc_product_post_class – افزودن کلاس های html اضافی به محصول
Syntax – سینتکس
(array) wc_product_post_class( (array) $classes, (string) $class = '', (string) $post_id = '' );
Parameters – پارامتر ها (3)
- 1- $classes (array)
- 2- $class (string)
- 3- $post_id (string)
Usage – نحوه استفاده
if ( !function_exists( 'wc_product_post_class' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php';
}
// The classes.
$classes = array();
// The class.
$class = '';
// The post id.
$post_id = '';
// NOTICE! Understand what this does before running.
$result = wc_product_post_class($classes, $class, $post_id);
Defined – محل تعریف
/includes/wc-template-functions.php
function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ) ) ) {
return $classes;
}
$product = wc_get_product( $post_id );
if ( $product ) {
$classes[] = 'product';
$classes[] = wc_get_loop_class();
$classes[] = $product->get_stock_status();
if ( $product->is_on_sale() ) {
$classes[] = 'sale';
}
if ( $product->is_featured() ) {
$classes[] = 'featured';
}
if ( $product->is_downloadable() ) {
$classes[] = 'downloadable';
}
if ( $product->is_virtual() ) {
$classes[] = 'virtual';
}
if ( $product->is_sold_individually() ) {
$classes[] = 'sold-individually';
}
if ( $product->is_taxable() ) {
$classes[] = 'taxable';
}
if ( $product->is_shipping_taxable() ) {
$classes[] = 'shipping-taxable';
}
if ( $product->is_purchasable() ) {
$classes[] = 'purchasable';
}
if ( $product->get_type() ) {
$classes[] = "product-type-" . $product->get_type();
}
if ( $product->is_type( 'variable' ) ) {
if ( ! $product->get_default_attributes() ) {
$classes[] = 'has-default-attributes';
}
if ( $product->has_child() ) {
$classes[] = 'has-children';
}
}
}
if ( false !== ( $key = array_search( 'hentry', $classes ) ) ) {
unset( $classes[ $key ] );
}
return $classes;
}
versions – نسخه ها
از نسخه : 2.1.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر