post_type ) {
$file = dirname(__FILE__) . '/templates/wc.php';
}
return $file;
}
/* Add WooCommerce elements in the page
1. Add WooCommerce container
2. Add Custom Style for WooCommerce Page
3. Add WooCommerce gallery
4. Add WooCommerce amp-carousel script
5. Remove Default Post Meta from header
6. Add WooCommerce Meta information
7. Add Product Description
*/
// 1. Add WooCommerce container
// Add container for WooCommerce elements
add_action('amp_woocommerce_after_the_content','amp_woocommerce_container_starts',9);
function amp_woocommerce_container_starts(){
echo '
' ;
}
add_action('amp_woocommerce_after_the_content','amp_woocommerce_container_ends',20);
function amp_woocommerce_container_ends(){
echo '
' ;
}
// 2. Add Custom Style for WooCommerce Page
add_action('amp_post_template_css','amp_woocommerce_custom_style');
function amp_woocommerce_custom_style() {
if ( function_exists( 'is_on_sale' ) ) {
global $woocommerce;
$amp_woocommerce_sale = $woocommerce->product_factory->get_product()->is_on_sale();
if ( $amp_woocommerce_sale == 1 ) { ?>
.amp-wp-article-featured-image::before {
content: 'Sale';
background: #0a89c0;
padding: 20px 15px;
border-radius: 50%;
color: #fff;
position: relative;
z-index: 1;
left: 5%px;
top: 30px;
}
.amp-woocommerce-container amp-carousel {
background: none;
}
.ampforwp-add-to-cart-button a {
background: #0a89c0;
color: #fff;
padding: 10px 8px;
text-decoration: none;
}
product_factory->get_product()->get_gallery_attachment_ids();
if ( $amp_woocommerce_gallery ) { ?>
post_type ) {
// add_filter( 'amp_post_article_footer_meta', 'amp_woocommerce_remove_comment_button' );
// }
// function amp_woocommerce_remove_comment_button( $meta_parts ) {
// foreach ( array_keys( $meta_parts, 'meta-comments-link', true ) as $key ) {
// unset( $meta_parts[ $key ] );
// }
// return $meta_parts;
// }
// 6. Add WooCommerce Meta information
add_filter( 'amp_post_article_header_meta', 'amp_woocommerce_add_wc_meta' );
function amp_woocommerce_add_wc_meta( $meta_parts ) {
$meta_parts[] = 'amp-woocommerce-meta-info';
return $meta_parts;
}
add_filter( 'amp_post_template_file', 'amp_woocommerce_add_wc_meta_path', 10, 3 );
function amp_woocommerce_add_wc_meta_path( $file, $type, $post ) {
if ( 'amp-woocommerce-meta-info' === $type && 'product' === $post->post_type ) {
$file = dirname( __FILE__ ) . '/templates/amp-woocommerce-meta-info.php';
}
return $file;
}
// 7. Add Product Description
add_action('amp_woocommerce_after_the_content','amp_woocommerce_add_product_description', 11);
function amp_woocommerce_add_product_description(){
woocommerce_template_single_excerpt();
}