Поисковая оптимизация
- 5 ответов
- 0 вопросов
1
Вклад в тег
var $warp_fragment_refresh = {
url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ),
type: 'POST',
success: function( data ) {
if ( data && data.fragments ) {
$.each( data.fragments, function( key, value ) {
$( key ).replaceWith( value );
});
$( document.body ).trigger( 'wc_fragments_refreshed' );
}
}
};
$('.entry-summary form.cart').on('submit', function (e)
{
e.preventDefault();
$('.entry-summary').block({
message: null,
overlayCSS: {
cursor: 'none'
}
});
var product_url = window.location,
form = $(this);
$.post(product_url, form.serialize() + '&_wp_http_referer=' + product_url, function (result)
{
var cart_dropdown = $('.widget_shopping_cart', result)
// update dropdown cart
$('.widget_shopping_cart').replaceWith(cart_dropdown);
// update fragments
$.ajax($warp_fragment_refresh);
$('.entry-summary').unblock();
});
});
<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" />
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_loop_add_to_cart', 30 );
// Change the add to cart text on single product pages
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( get_the_ID() == $_product->get_ID() ) {
return __('Already in cart - Add Again?', 'woocommerce');
}
}
return __('Add to cart', 'woocommerce');
}
// Change the add to cart text on product archives
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
function woo_archive_custom_cart_button_text() {
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( get_the_ID() == $_product->get_ID() ) {
return __('Already in cart', 'woocommerce');
}
}
return __('Add to cart', 'woocommerce');
}