"The Oxygen User's paradise"
How It Works?
Websites
All
Add Your Work
Elements
Buttons
Links
Sliders
Hovers
Snippets
ACF
WooCommerce
Blogs
Login here

Latest Snippets

[WooCommerce] External Product Links Open in a New Tab

https://www.tychesoftwares.com/how-to-make-woocommerce-external-product-links-open-in-a-new-tab/

<?php

// This will take care of the Buy Product button below the external product on the Shop page.
add_filter( 'woocommerce_loop_add_to_cart_link', 'ts_external_add_product_link' , 10, 2 );

// Remove the default WooCommerce external product Buy Product button on the individual Product page.
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );

// Add the open in a new browser tab WooCommerce external product Buy Product button.
add_action( 'woocommerce_external_add_to_cart', 'ts_external_add_to_cart', 30 );


function ts_external_add_product_link( $link ) {
global $product;

if ( $product->is_type( 'external' ) ) {

$link = sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s" target="_blank">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $class ) ? $class : 'button product_type_external' ),
esc_html( $product->add_to_cart_text() )
);
}

return $link;
}

function ts_external_add_to_cart() {
global $product;

if ( ! $product->add_to_cart_url() ) {
return;
}

$product_url = $product->add_to_cart_url();
$button_text = $product->single_add_to_cart_text();

/**
* The code below outputs the edited button with target="_blank" added to the html markup.
*/
do_action( 'woocommerce_before_add_to_cart_button' ); ?>

<p class="cart">
<a href="<?php echo esc_url( $product_url ); ?>" rel="nofollow" class="single_add_to_cart_button button alt" target="_blank">
<?php echo esc_html($button_text ); ?></a>
</p>

<?php do_action( 'woocommerce_after_add_to_cart_button' );

}

[WooCommerce] Change the calculation date for orders

WooCommerce Cancel Abandoned Order Plugin

function woa_date_order_hook( $old_date, $gateway, $mode ) {
// For example, change date only for cheque.
if ( 'bacs' == $gateway ) {
$old_date = strtotime( 'today -10 weekdays' );
}

return $old_date;
}
add_filter( 'woo_cao_date_order', 'woa_date_order_hook', 10, 3 );

[WooCommerce] Hide Products Stock by Post ID

SRACKY KAMO SRACKY

function mwo_hide_id_stock( $html, $product ) {
if ( is_single([8176,1335,1312,1343,1337,9617]) && $product->is_in_stock() ) {
return '';
}
return $html;
}
add_filter( 'woocommerce_get_stock_html', 'mwo_hide_id_stock', 10, 2 );

[WooCommerce] Hide Virtual Products Stock

SRACKY KAMO SRACKY

function mwo_hide_virtual_stock( $html, $product ) {
if ( $product-> is_virtual('yes') && $product->is_in_stock() ) {
return '';
}
return $html;
}
add_filter( 'woocommerce_get_stock_html', 'mwo_hide_virtual_stock', 10, 2 );

Rename "Shop" in Product Archive Title

Testing content

add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return "My new title";
}
}
appsarrow-upbrackets-curlycorner-down-right-altexclamation-circlelayers-alt