WP: 3.71
Theme: Jupiter (artbees) v.3.02
URL: http://thefastlearners.com/store/
Hi all,
I have some Woocommerce products that are external linking out to amazon or other sites.
My goal is to link these products to their external pages directly from the store page, without the detailpage!
Already tried the visibility option extension which didnât change a thing.
Here is the original content-product.php excerpt:
`
$mk_add_to_cart = ‘id ) ).’” class=”add_to_cart_button”>’. apply_filters( ‘out_of_stock_add_to_cart_text’, ( ‘READ MORE’, ‘woocommerce’ ) ).”;
$out_of_stock_badge = ”.( ‘OUT OF STOCK’, ‘woocommerce’ ).”;
}
else { ?>
switch ( $product->product_type ) {
case "external" :
$link = apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
$label = apply_filters( 'external_add_to_cart_text', __( 'Read More', 'woocommerce' ) );
$icon_class = 'mk-moon-search-3';
break;
default :
$link = apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
$label = apply_filters( 'add_to_cart_text', __( 'ADD TO CART', 'woocommerce' ) );
$icon_class = 'mk-moon-cart-plus';
break;
}
if ( $product->product_type != 'external' ) {
$mk_add_to_cart = '<a href="'. $link .'" rel="nofollow" data-product_id="'.$product->id.'" class="add_to_cart_button product_type_'.$product->product_type.'"><i class="'.$icon_class.'"></i>'. $label.'</a>';
}
else {
$mk_add_to_cart = '';
}
}`
Which I changed to
´<?php
$mk_add_to_cart = '**;<a href="<?php echo esc_url( $product_url )**; ?>" rel="nofollow" class="single_add_to_cart_button shop-flat-btn shop-skin-btn alt"></a>';
$out_of_stock_badge = '<span class="mk-out-stock">'.__( 'OUT OF STOCK', 'woocommerce' ).'</span>';
}
else { ?>
switch ( $product->product_type ) {
case "external" :
$link = apply_filters( 'external_add_to_cart_url', esc_url( $product_url ) );
$label = apply_filters( 'external_add_to_cart_text', __('Read More', 'woocommerce') );
$icon_class = 'mk-moon-search-3';
break;
default :
$link = apply_filters( 'add_to_cart_url', esc_url( $product_url ) );
$label = apply_filters( 'add_to_cart_text', __( 'ADD TO CART', 'woocommerce' ) );
$icon_class = 'mk-moon-cart-plus';
break;
}
if ( $product->product_type != 'external' ) {
$mk_add_to_cart = '<a href="'. $link .'" rel="nofollow" data-product_id="'.$product->id.'" class="add_to_cart_button product_type_'.$product->product_type.'"><i class="'.$icon_class.'"></i>'. $label.'</a>';
}
else {
$mk_add_to_cart = '';
}`
Without any results except that I donât get any button to add anything.
from the external.php template I already figured out that the command should be something like
<?php echo esc_url( $product_url ); ?>
but I donât get where to put/link it.
Would be wonderful if you can help me out here. Once I got that working I can change the links of the title and image myself.
Thanks,
Mattis
You should try
$product->product_url
instead of plain$product_url
.That worked for me on the
content-product.php
page.