Advertisement
borkolivic

Custom subtitle inside shop loop

Dec 26th, 2021
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. add_action ('woocommerce_product_options_general_product_data', 'subtitle_product_data_metabox');
  2. function subtitle_product_data_metabox() {
  3.    echo '<div class="options_group">';
  4.    woocommerce_wp_text_input (array (
  5.       'id'                => 'product_subtitle_inside_loop',
  6.       'value'             => get_post_meta (get_the_ID(), 'product_subtitle_inside_loop', true),
  7.       'label'             => 'Product subtitle',
  8.       'description'       => 'Subtitle text to appear between title and price'
  9.   ));
  10.    echo '</div>';
  11. }
  12.  
  13. add_action ('woocommerce_process_product_meta', 'save_subtitle_field_on_update', 10, 2);
  14. function save_subtitle_field_on_update ($id, $post) {
  15.       update_post_meta ($id, 'product_subtitle_inside_loop', $_POST['product_subtitle_inside_loop']);
  16. }
  17.  
  18. add_action( 'woocommerce_after_shop_loop_item_title', 'show_subtitle_after_shop_loop_item_title', 1, 0 );
  19. function show_subtitle_after_shop_loop_item_title() {
  20.     global $product;
  21.     $product_subtitle_inside_loop = $product->get_meta ('product_subtitle_inside_loop');
  22.     echo $product_subtitle_inside_loop;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement