dongzhong5967 2014-08-26 11:30
浏览 36

woocommerce短代码不适用于所有帖子

I have created a short code to display short description in woo commerce but it is not working on all posts. It is displaying the short description on some posts and not on others.

Function to create that short code in functions.php

    function product_shortdesc_shortcode( $atts ){
    // use shortcode_atts() to set defaults then extract() to variables
    extract( shortcode_atts( array( 'id' => false ), $atts ) );

    // if an $id was passed, and we could get a Post for it, and it's a product....
    if ( ! empty( $id ) && null != ( $product = get_post( $id ) ) && $product->post_type = 'product' ){
        // apply woocommerce filter to the excerpt
        echo apply_filters( 'woocommerce_short_description', $product->post_excerpt );
    }
}
// process [product_shortdesc] using product_shortdesc_shortcode()
add_shortcode( 'product_shortdesc', 'product_shortdesc_shortcode' );

The way i am getting the data in my single.php file

$custom = get_post_custom(get_the_ID());
$my_custom_field = $custom['woo_id'];
foreach ( $my_custom_field as $key => $value ) {
echo do_shortcode('[product_shortdesc id='.$value.']');
}

PS: in my normal post i have a custom field which has the value of product id of the product in woo commerece.

  • 写回答

2条回答 默认 最新

  • dtwzwmv87399 2014-08-26 11:46
    关注

    Your issue is that you are expecting shortcodes to function which no longer exist. On new installs, these pages won't be created, but if you are updating you may already have those pages in place.

    Although the upgrade script does attempt to trash them for you, this might not have happened if they were customised. Delete them. Delete edit-account and change password, then go to your 'my account' page and click the change password/edit account links. You'll be taken to and endpoint which offers the same functionality.

    Thanks

    评论

报告相同问题?