Answers for "how to update only attributes in woocommerce"

2

add custom field to variation woocommerce

/**
 * @snippet       Add Custom Field to Product Variations - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=73545
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// -----------------------------------------
// 1. Add custom field input @ Product Data > Variations > Single Variation
 
add_action( 'woocommerce_variation_options_pricing', 'bbloomer_add_custom_field_to_variations', 10, 3 );
 
function bbloomer_add_custom_field_to_variations( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => 'custom_field[' . $loop . ']',
'class' => 'short',
'label' => __( 'Custom Field', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'custom_field', true )
)
);
}
 
// -----------------------------------------
// 2. Save custom field on product variation save
 
add_action( 'woocommerce_save_product_variation', 'bbloomer_save_custom_field_variations', 10, 2 );
 
function bbloomer_save_custom_field_variations( $variation_id, $i ) {
$custom_field = $_POST['custom_field'][$i];
if ( isset( $custom_field ) ) update_post_meta( $variation_id, 'custom_field', esc_attr( $custom_field ) );
}
 
// -----------------------------------------
// 3. Store custom field value into variation data
 
add_filter( 'woocommerce_available_variation', 'bbloomer_add_custom_field_variation_data' );
 
function bbloomer_add_custom_field_variation_data( $variations ) {
$variations['custom_field'] = '<div class="woocommerce_custom_field">Custom Field: <span>' . get_post_meta( $variations[ 'variation_id' ], 'custom_field', true ) . '</span></div>';
return $variations;
}
Posted by: Guest on September-08-2020
0

display only price from selected variable woocommerce

add_action('woocommerce_before_add_to_cart_form', 'selected_variation_price_replace_variable_price_range');
function selected_variation_price_replace_variable_price_range(){
    global $product;

    if( $product->is_type('variable') ):
    ?><style> .woocommerce-variation-price {display:none;} </style>
    <script>
    jQuery(function($) {
        var p = 'p.price';

        $('form.cart').on('show_variation', function( event, data ) {
            $(p).html(data.price_html);
        }).on('hide_variation', function( event ) {
            $(p).html($(a).html());
        });
    });
    </script>
    <?php
    endif;
}
Posted by: Guest on March-05-2021
1

WooCommerce attributes

defauls:

show selected products by ID
[products limit="16" columns="4" ids="766,620,1033,624,626,960, 629,635,861"]

show products ob SALE
[products limit="" columns="4" orderby="popularity" class="quick-sale" on_sale="true"]

show selected category
[products limit="8" columns="4" category="hoodies, tshirts"]

show products by tags
[products tag="hoodie"]

special:
[lf_woo_products_carousel id="an_uniq_id" categories="selected category" loop="1" selected_products_tab="0"] => show category in carucell
"id" => the uniq id of a product or a shortcode with carusell
"col" => number of col's
"tablet_col" => number of col's in tablete
"mobile_col" => number of col's in mobile
"class" => Ex. "hight-400"
"direction" => of the carusella "horizontal" | "vertical"
"loop" => if it will loop or not "0"
"delay" => the time for shifting in milisec "3000"
"speed" => thr rotation spees "300"
"centered" => of the product "0"
"mousewheel" => will the mouse scroll thr carusel or not "0"
"nevigation" => show the arrow on the sides "1"
"pagination" => show the numbers of the pics "1"
"scrollbar" => show the scroll bars "0"
"photoswipe" => swipting the photos "0"
"categories" => the selected category to show spreted by comma (,) "null"
"tags" => the selected tags to show spreted by comma (,) "null"
"selected_products_tab" => whitch tab to show "0"
"new_products_tab" => show the new products "1"
Posted by: Guest on August-10-2020

Code answers related to "how to update only attributes in woocommerce"

Browse Popular Code Answers by Language