tag - wordpress php get post title by id
Woocomerce establece la categoría carrito mínimo (3)
Prueba este código, espero que esto te ayude
http://wordpress-code-snippets.blogspot.in/2017/02/woocommerce-set-minimum-quantity-for.html
add_action( ''woocommerce_check_cart_items'', ''restrict_product_quantity'' );
function restrict_product_quantity() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
$pd_min_quantity= array(
array( ''id'' => 3587, ''min'' => 99),
array( ''id'' => 2554, ''min'' => 87),
array( ''id'' => 5587, ''min'' => 52),
array( ''id'' => 4488, ''min'' => 40),
array( ''id'' => 2555, ''min'' => 80),
);
$i = 0;
$odd_prod = array();
foreach( $woocommerce->cart->cart_contents as $pd_cart ) {
foreach( $pd_min_quantity as $pd_quantity ) {
if( $pd_quantity[''id''] == $pd_cart[''product_id''] ) {
if( $pd_cart[''quantity''] < $pd_quantity[''min''] ) {
$odd_prod[$i][''id''] = $pd_cart[''product_id''];
$odd_prod[$i][''in_cart''] = $pd_cart[''quantity''];
$odd_prod[$i][''min_req''] = $pd_quantity[''min''];
}
}
}
$i++;
}
if( is_array( $odd_prod) && count( $odd_prod ) > 1 ) {
$message = ''<strong>Minimum quantity per product should be added.</strong><br />'';
foreach( $odd_prod as $odd_prods ) {
$message .= get_the_title( $odd_prods[''id''] ) .'' requires a minimum quantity of ''
. $odd_prods[''min_req'']
.''. You currently have: ''. $odd_prods[''in_cart''] .''.<br />'';
}
wc_add_notice( $message, ''error'' );
}
}
}
Me gustaría el precio de bloque para la categoría woocomerce específica, ahora trabajo solo toda la categoría woocomerce mi código. Mi nombre de categoría es: stock. Solo quiero usar para esta categoría.
Quiero que un usuario si compre una categoría de stock tenga que comprar un mínimo de 1200.
// Set a minimum dollar amount per order
add_action( ''woocommerce_check_cart_items'', ''spyr_set_min_total'' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set minimum cart total
$minimum_cart_total = 1200;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// Compare values and add an error is Cart''s total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if( $total <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( ''<strong>A Minimum of %s %s is required before checking out.</strong>''
.''<br />Current cart/'s total: %s %s'',
$minimum_cart_total,
get_option( ''woocommerce_currency''),
$total,
get_option( ''woocommerce_currency'') ),
''error'' );
}
}
}
Este es mi código, lo he insertado en function.php: Mi ID de categoría: http://goo.gl/R197Bz
// start code
add_action( ''woocommerce_check_cart_items'', ''spyr_set_min_total'' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce, $product;
$i=0;
//loop through all cart products
foreach ( $woocommerce->cart->cart_contents as $product ) :
// Set minimum cart total
$minimum_cart_total = 1200;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// See if any product is from the STOCK category or not
if ( has_term( ''112'', ''product_cat'', $product[''product_id''] ) ) :
//Get price of that product
$regular_price = get_post_meta($product[''product_id''], ''_sale_price'', true); //change to _sale_price if it is in sale
//echo $regular_price."<br>";
$total = $regular_price * $product[''quantity''];
//echo $total."<br>";
$subtotal_cat += $total; //get total of
//echo $subtotal_cat;
//$category_price += ( $product[''line_subtotal''] + $product[''line_subtotal_tax''] );
endif;
endforeach;
foreach ( $woocommerce->cart->cart_contents as $product ) :
if ( has_term( ''11'', ''product_cat'', $product[''product_id''] ) ) :
// Compare values and add an error is Cart''s total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if( $subtotal_cat <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( ''<strong>A Minimum of %s %s is required from stock category before checking out.</strong>''
.''<br />Current cart/'s total: %s %s'',
$minimum_cart_total,
get_option( ''woocommerce_currency''),
$subtotal_cat,
get_option( ''woocommerce_currency'') ),
''error'' );
}
endif;
endforeach;
}
}
// end
Pruebe el siguiente código:
add_action( ''woocommerce_check_cart_items'', ''spyr_set_min_total'' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce, $product;
$i=0;
//loop through all cart products
foreach ( $woocommerce->cart->cart_contents as $product ) :
// Set minimum cart total
$minimum_cart_total = 1200;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// See if any product is from the STOCK category or not
if ( has_term( ''112'', ''product_cat'', $product[''product_id''] ) ) :
//Get price of that product
$regular_price = get_post_meta($product[''product_id''], ''_sale_price'', true); //change to _sale_price if it is in sale
//echo $regular_price."<br>";
$total = $regular_price * $product[''quantity''];
//echo $total."<br>";
$subtotal_cat += $total; //get total of
//echo $subtotal_cat;
//$category_price += ( $product[''line_subtotal''] + $product[''line_subtotal_tax''] );
endif;
endforeach;
foreach ( $woocommerce->cart->cart_contents as $product ) :
if ( has_term( ''112'', ''product_cat'', $product[''product_id''] ) ) :
// Compare values and add an error is Cart''s total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if( $subtotal_cat <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( ''<strong>A Minimum of %s %s is required from stock category before checking out.</strong>''
.''<br />Current cart/'s total: %s %s'',
$minimum_cart_total,
get_option( ''woocommerce_currency''),
$subtotal_cat,
get_option( ''woocommerce_currency'') ),
''error'' );
}
endif;
endforeach;
}
}
Déjame saber la salida ...