Skip to content

Instantly share code, notes, and snippets.

@manuelhudec
Created June 12, 2021 18:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelhudec/6953326e86b348d033d22ad9f540ddc4 to your computer and use it in GitHub Desktop.
Save manuelhudec/6953326e86b348d033d22ad9f540ddc4 to your computer and use it in GitHub Desktop.
WooCommerce - Product Subtitle under Product Title
//Register the product custom field
add_action( 'woocommerce_product_options_inventory_product_data', 'my_woocommerce_product_subheading' );
function my_woocommerce_product_subheading() {
$args = array(
'label' => 'Produkt-Untertitel', // Text in Label
'placeholder' => 'Produkt-Untertitel',
'id' => 'product_subheading', // required
'name' => 'product_subheading',
'desc_tip' => 'Produkt-Untertitel eingeben',
);
woocommerce_wp_text_input( $args );
}
//Save the custom field as product custom post meta
add_action( 'woocommerce_process_product_meta', 'my_woocommerce_save_product_subheading' );
function my_woocommerce_save_product_subheading( $post_id ) {
$product = wc_get_product( $post_id );
$title = isset( $_POST['product_subheading'] ) ? $_POST['product_subheading'] : '';
$product->update_meta_data( 'product_subheading', sanitize_text_field( $title ) );
$product->save();
}
//Display the custom field on product page loop below the title
add_action( 'blocksy:woocommerce:product-single:price:before', 'subheading_display_below_title', 2 );
function subheading_display_below_title(){
global $product;
// Get the custom field value
$subheading = get_post_meta( $product->get_id(), 'product_subheading', true );
// Display
if( ! empty($subheading) ){
echo '<div class="subheading">'.$subheading.'</div>';
}
}
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 11 );
@slw85
Copy link

slw85 commented Jun 12, 2021

Hi are you able to help me trouble shoot a woocommerce product styling?

scott.wilson@twiz.io

@manuelhudec
Copy link
Author

Hi are you able to help me trouble shoot a woocommerce product styling?

scott.wilson@twiz.io

Related to the code here?

@slw85
Copy link

slw85 commented Jun 12, 2021

Hi are you able to help me trouble shoot a woocommerce product styling?
scott.wilson@twiz.io

Related to the code here?

No but woocommerce related - I am using a subscription plugin that has auto inserted text after pricing. I can't seem to figure it out, its creating sub info to the price script,

< small class="wcsatt-sub-options" > < span class="wcsatt-dash" >—< /span > available on subscription< /small >

this string is auto-inserting and I am at a loss on how to hide it/keep it from showing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment