WOO钩子使用

Published
2022-12-16
浏览次数 :  21

/*-----------------------------------------------------------------------------------*/
# WOOCOMMERCE
/*-----------------------------------------------------------------------------------*/
add_action('woocommerce_before_main_content', 'tie_woocommerce_wrapper_start', 22);
function tie_woocommerce_wrapper_start() {
	echo '<div class="post-listing"><div class="post-inner">';
}

add_action('woocommerce_after_main_content', 'tie_woocommerce_wrapper_start2', 11);
function tie_woocommerce_wrapper_start2() {
  echo '</div></div>';
}

add_action('woocommerce_before_shop_loop', 'tie_woocommerce_wrapper_start3', 33);
function tie_woocommerce_wrapper_start3() {
  echo '<div class="clear"></div>';
}

add_action('woocommerce_before_shop_loop_item_title', 'tie_woocommerce_wrapper_product_img_start', 9);
function tie_woocommerce_wrapper_product_img_start() {
  echo '<div class="product-img">';
}

add_action('woocommerce_before_shop_loop_item_title', 'tie_woocommerce_wrapper_product_img_end', 11);
function tie_woocommerce_wrapper_product_img_end() {
  echo '</div>';
}

add_filter('loop_shop_columns', 'tie_woocommerce_loop_shop_columns', 99, 1);
function tie_woocommerce_loop_shop_columns() {
    return 3;
}

add_filter( 'woocommerce_output_related_products_args', 'tie_woocommerce_related_products_args' );
function tie_woocommerce_related_products_args( $args ){

	$args['posts_per_page'] = 3;
	$args['columns'] = 3;
	return $args;
}

add_filter( 'woocommerce_single_product_image_thumbnail_html', 'tie_woocommerce_single_product_image_html', 20, 2 );
function tie_woocommerce_single_product_image_html( $html, $attachment_id ){

	$full_size_image = wp_get_attachment_image_src( $attachment_id, 'full' );
	$zoom_trigger = 'class="woocommerce-product-gallery__image"><a href="'. esc_url( $full_size_image[0] ) .'" class="woocommerce-product-gallery__trigger"><span class="fa fa-search-plus"></span></a>';

	$html = str_replace( 'class="woocommerce-product-gallery__image">', $zoom_trigger, $html );

	return $html;
}

  • 标签1
  • 标签1
  • 标签1
Top