• Resolved briify

    (@briify)


    Hi,

    We need to remove everything before a specific character in a product attribute. Example:
    Product attribute (sizes): 10042-25-XS
    We want to change it to only: XS

    In the product attribute we have added the following:
    [strtest({merchant_product_id[1]})]
    Screenshot:
    https://prnt.sc/pn27oq

    So far we have added the following code to our functions.php, but it doesn’t seem to work:

    function strtest( $str, $char, $strpos) {
    		$str = merchant_product_id[1]; 
                    $char =  " - "; 
    		$strpos = strpos($str, $char); 
    		$str = substr($str, $strpos+strlen($char)); //Extract the substring after the separator
    		echo $str;
    }

    Screenshot:
    https://prnt.sc/pn27a1

    Hope you can help 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @briify

    Please try this function:

    function my_get_value( $attribute = '' ) {
    	if ( empty( $attribute ) ) return;
    	$attribute = explode( "-", $attribute );
    	return array_pop( $attribute );
    }
    Thread Starter briify

    (@briify)

    Hi again,

    Your function is working, so that is great. But I can see now, that I didn’t formulate me right since we also want to remove the - after everything before that character is removed.

    To make it clear:
    Screenshot of how the function is working now:
    https://prnt.sc/pn849f
    We then want to remove the - too.

    Thank you already 🙂

    Thread Starter briify

    (@briify)

    Hi,

    I tried reuploading the CSV-file and rerun code again, now it seems to work!

    Thank you 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Remove everything before specific character’ is closed to new replies.