Answers for "add to cart"

PHP
0

add_to_cart how to call it woocommerce

add_action( 'template_redirect', 'quadlayers_add_to_cart_function' );

function quadlayers_add_to_cart_function () {

    $product_id = 1326;

    if ( WC()->cart->get_cart_contents_count() == 0 ) {

        WC()->cart->add_to_cart( $product_id );

    }

}
Posted by: Guest on December-08-2020
0

add to cart

function remove_loop_button(){
 if (in_array( 10, $product->category_ids))
  remove_action(‘woocommerce_after_shop_loop_item’,‘woocommerce_template_loop_add_to_cart’, 10);
}
add_action(‘init’,’remove_loop_button’);

add_action(‘woocommerce_after_shop_loop_item’,’replace_add_to_cart’);
function replace_add_to_cart() {
global $product;
$link = $product->get_permalink();
echo ‘<a href=”‘.esc_attr($link).'”>Try Now</a>’;
}
Posted by: Guest on October-28-2021
0

code to add to cart by javascript

// Appends the required hidden values to PayPal's form before submitting

populatePayPalForm: function() {
    var self = this;
    if( self.$paypalForm.length ) {
        var $form = self.$paypalForm;
        var cart = self._toJSONObject( self.storage.getItem( self.cartName ) );
        var shipping = self.storage.getItem( self.shippingRates );
        var numShipping = self._convertString( shipping );
        var cartItems = cart.items;
        var singShipping = Math.floor( numShipping / cartItems.length );

        $form.attr( "action", self.paypalURL );
        $form.find( "input[name='business']" ).val( self.paypalBusinessEmail );
        $form.find( "input[name='currency_code']" ).val( self.paypalCurrency );

        for( var i = 0; i < cartItems.length; ++i ) {
            var cartItem = cartItems[i];
            var n = i + 1;
            var name = cartItem.product;
            var price = cartItem.price;
            var qty = cartItem.qty;

            $( "<div/>" ).html( "<input type='hidden' name='quantity_" + n + "' value='" + qty + "'/>" ).
            insertBefore( "#paypal-btn" );
            $( "<div/>" ).html( "<input type='hidden' name='item_name_" + n + "' value='" + name + "'/>" ).
            insertBefore( "#paypal-btn" );
            $( "<div/>" ).html( "<input type='hidden' name='item_number_" + n + "' value='SKU " + name + "'/>" ).
            insertBefore( "#paypal-btn" );
            $( "<div/>" ).html( "<input type='hidden' name='amount_" + n + "' value='" + self._formatNumber( price, 2 ) + "'/>" ).
            insertBefore( "#paypal-btn" );
            $( "<div/>" ).html( "<input type='hidden' name='shipping_" + n + "' value='" + self._formatNumber( singShipping, 2 ) + "'/>" ).
            insertBefore( "#paypal-btn" );

        }

    }
}
Posted by: Guest on February-11-2021

Code answers related to "add to cart"

Browse Popular Code Answers by Language