woocommerce / woocommerce-subscriptions-custom-price-string

Customize the price displayed to your customers for subscription products (or non-subscription product).
GNU General Public License v3.0
62 stars 11 forks source link

Custom price string cannot be saved on Variable Subscriptions. #22

Closed melek closed 2 years ago

melek commented 3 years ago

Describe the issue Setting a custom 'From' price string on a variable subscription doesn't work - saving it results in the field being blank upon reload, and the from price isn't customized on the front-end. The custom price strings per-variation work just fine.

Steps to replicate On WordPress 5.7.2 with only Storefront, WooCommerce, Subscriptions, and Subs Custom Price String active and up to date:

What should happen instead The custom price string should be saved and displayed as expected.

Additional Information

melek commented 3 years ago

Additionally, this seems related somewhat to issue #12 (though that looks like it was about Variable Products rather than Subscriptions).

16 seems possibly related since it deals with the from price code, but I can't see why it would make a difference from the commit.

Rypheal commented 3 years ago

I face the same issue, the custom 'from price' is being reset on product save (variable subscription product type). Can someone please have a look into this?

Appreciate it a lot!

Or @melek : did you find a way to workaround this issue?

Rypheal commented 3 years ago

@bernattorras : could you perhaps have a look into this issue? Would be very appreciate it.

fschmittlein commented 3 years ago

@bernattorras : We have the same issue. Please, can you fix it?

apostle-coffee commented 3 years ago

Unfortunately this issue is happening for us too. On our Variable Subscription page the 'Custom from string' tab is visible and you can input this field, but when publishing/updating the page it vanishes and defaults back to the unwanted standard text. A fix for this would be great please!

RidgeTek commented 3 years ago

Same problem here - is there a resolution?

ghost commented 2 years ago

Same problem here - update the field does not save properly.

wpniall commented 2 years ago

Another report in 32581901-hc

cmorillo commented 2 years ago

Hi , I have managed to fix it. You have to change the code though:

On the woocommerce-subscriptions-custom-pricestring. php there is a function, you have to change the order there:

/**
 * Save the custom price string in the current product's '_custom_price_string' meta
 *
 * @access public
 * @param mixed $post_id
 * @return void
 */
function save_custom_price_string( $post_id ) {
    if ( isset( $_REQUEST['_custom_price_string'] ) ) {

        // If it is coming from a variable subscription product, skip it (as we already use the woocommerce_save_product_variation hook for this purpose).
        if ( is_array( $_REQUEST['_custom_price_string'] ) ) {
            return;
        }

        $custom_price_string = wp_unslash( $_REQUEST['_custom_price_string'] );
        update_post_meta( $post_id, '_custom_price_string', $custom_price_string );

    }

    if ( isset( $_REQUEST['_custom_from_string'] ) ) {

        $custom_from_string = wp_unslash( $_REQUEST['_custom_from_string'] );
        update_post_meta( $post_id, '_custom_from_string', $custom_from_string );

    }
}
add_action( 'save_post', 'save_custom_price_string', 11 );

To BECOME:

/**
 * Save the custom price string in the current product's '_custom_price_string' meta
 *
 * @access public
 * @param mixed $post_id
 * @return void
 */
function save_custom_price_string( $post_id ) {

        if ( isset( $_REQUEST['_custom_from_string'] ) ) {

        $custom_from_string = wp_unslash( $_REQUEST['_custom_from_string'] );
        update_post_meta( $post_id, '_custom_from_string', $custom_from_string );

    }
    if ( isset( $_REQUEST['_custom_price_string'] ) ) {

        // If it is coming from a variable subscription product, skip it (as we already use the woocommerce_save_product_variation hook for this purpose).
        if ( is_array( $_REQUEST['_custom_price_string'] ) ) {
            return;
        }

        $custom_price_string = wp_unslash( $_REQUEST['_custom_price_string'] );
        update_post_meta( $post_id, '_custom_price_string', $custom_price_string );

    }

}
add_action( 'save_post', 'save_custom_price_string', 11 );

@bernattorras how could we update this? or you will do it?

RidgeTek commented 2 years ago

Is this going to be updated in the next update?

neilmccreadie commented 2 years ago

Another report in 4554924-zen

bernattorras commented 2 years ago

Sorry for the delay! I've updated the plugin with a fix that should prevent this conflict!

Please reopen the issue if the problem persits!

fontaholic commented 2 years ago

i added this fix to my site. although the input box appears on all variable products types, it only displays the text added on those with Variable Subscriptions. it would be nice if it worked with other variations and simple products as well.

melek commented 2 years ago

@fontaholic I like that idea; I think that opening a new issue would be the best way to suggest it, so it can be tracked separately.